MBMLRuntimeFunctions Class Reference
Inherits from | NSObject |
---|---|
Declared in | MBMLRuntimeFunctions.h |
Overview
This class implements a set of MBML functions and supporting methods that provide access to Objective-C runtime information.
These functions are exposed to the Mockingbird environment via
<Function ... />
declarations in the MBDataEnvironmentModule.xml
file.
For more information on MBML functions, see the MBMLFunction
class.
Helper method for looking up classes
+ resolveClass:error:
Given a Class or a string containing the name of an Objective-C class, this method returns a Class object.
+ (Class)resolveClass:(id)resolveCls error:(inout MBMLFunctionError **)errPtr
Parameters
resolveCls |
A |
---|---|
errPtr |
If non- |
Return Value
A Class
object representing the specified class, or nil
if
the specified class was not recognized by the Objective-C runtime.
Discussion
Note: This method is not exposed to the Mockingbird environment as a an MBML function.
Declared In
MBMLRuntimeFunctions.h
Looking up Classes
+ classExists:
Determines whether a given class exists in the Objective-C runtime.
+ (id)classExists:(NSString *)className
Parameters
className |
The function’s input parameter. |
---|
Return Value
If there is a class with the given name, @YES
is returned.
Otherwise, @NO
.
Discussion
This Mockingbird function accepts a single string expression yielding the name of the class.
Expression usage
^classExists(NSString)
The expression above would return YES
, because the class
NSString
is part of the iOS SDK.
Declared In
MBMLRuntimeFunctions.h
+ getClass:
Returns the Class
object for the given class name.
+ (id)getClass:(NSString *)className
Parameters
className |
The function’s input parameter. |
---|
Return Value
If there is a class with the given name, the corresponding
Class
object is returned. Otherwise, nil
is returned.
Discussion
This Mockingbird function accepts a single string expression yielding the name of the class.
Expression usage
Note: This function is exposed to the Mockingbird environment with a name that differs from that of its implementing method:
^class(NSString)
The expression above would return the Class
object representing the
NSString
class.
Declared In
MBMLRuntimeFunctions.h
Accessing singleton instances
+ singleton:
Returns the singleton instance of a given class.
+ (id)singleton:(id)forCls
Parameters
forCls |
The function’s input parameter. |
---|
Return Value
If there is a class with the given name, the corresponding
Class
object is returned. Otherwise, nil
is returned.
Discussion
This Mockingbird function accepts a single object expression yielding either
a Class
object or an NSString
containing the name of an Objective-C class.
If the specified class responds to the selector instance
, this function
returns that instance.
Expression usage
^singleton(MBServiceManager)
The expression above would return the singleton instance of the
MBServiceManager
class.
Declared In
MBMLRuntimeFunctions.h
Getting a class's hierarchy
+ inheritanceHierarchyForClass:
Returns an array containing the inheritance hierarchy of a given class.
+ (id)inheritanceHierarchyForClass:(id)forCls
Parameters
forCls |
The function’s input parameter. |
---|
Return Value
An array containing the Objective-C class hierarchy for the
specified class. If no such class was found, nil
is returned.
Discussion
This Mockingbird function accepts a single parameter, the class expression,
an object expression yielding either a Class
object or an NSString
containing the name of an Objective-C class.
The first item in the returned array will contain the Class
object
representing the class identified by class.
Each subsequent item in the array will contain a Class
representing the
superclass of the item that preceded it.
The last item in the returned array will contain the root class of the
hierarchy (which is usually NSObject
).
Expression usage
^inheritanceHierarchyForClass(NSMutableString)
The expression above would return an array containing three objects: the
Class
object for the NSMutableString
class, the Class
object for
NSString
, and finally the Class
for NSObject
.
Declared In
MBMLRuntimeFunctions.h
Checking for method implementations
+ objectRespondsToSelector:
Determines whether a given object instance responds to a specific Objective-C message selector.
+ (id)objectRespondsToSelector:(NSArray *)params
Parameters
params |
The function’s input parameters. |
---|
Return Value
If object instance referenced in the object expression
responds to the selector specified in the selector expression,
the return value will be @YES
. Otherwise, @NO
will be returned.
Discussion
This Mockingbird function accepts two pipe-separated parameters:
The object, an object expression yielding an
NSObject
instance, andThe selector, a string expression yielding the selector name.
Expression usage
Note: This function is exposed to the Mockingbird environment with a name that differs from that of its implementing method:
^respondsToSelector($myName|isEqualToString:)
The expression above would evaluate to true if the expression $myName
yields an NSString
instance (or an instance of any other class that
responds to the isEqualToString:
message).
Declared In
MBMLRuntimeFunctions.h
+ classRespondsToSelector:
Determines whether a given class responds to a specific Objective-C message selector.
+ (id)classRespondsToSelector:(NSArray *)params
Parameters
params |
The function’s input parameters. |
---|
Return Value
If the Objective-C class referenced in the class expression
responds to the selector specified in the selector expression,
the return value will be @YES
. Otherwise, @NO
will be returned.
Discussion
This Mockingbird function accepts two pipe-separated parameters:
The class, an object expression yielding either a
Class
object or anNSString
containing the name of an Objective-C classThe selector, a string expression yielding the selector name.
Expression usage
Note: This function is exposed to the Mockingbird environment with a name that differs from that of its implementing method:
^instancesRespondToSelector(NSString|availableStringEncodings)
The expression above evaluates to @YES
because the NSString
class responds
to the availableStringEncodings
message.
Declared In
MBMLRuntimeFunctions.h