Objective-C Class Introspection

Class Introspection

Determine whether an objective-C object is an instance of a class

[obj isMemberOfClass:someClass];

Determine whether an objective-C object is an instance of a class or its descendants

[obj isKindOfClass:someClass];

The version of a class

[MyString version]

Find the class of an Objective-C object

Class c = [obj1 class];
Class c = [NSString class];

Verify 2 Objective-C objects are of the same class

[obj1 class] == [obj2 class]

Objective-C Selector

Objective-C selector is an unique identifier for an Objective-C object's method

To retrieve a selector of a method

SEL mySelector;
mySelector = @selector(setValue:param2:);

To retrieve a selector by a string value

mySelector = NSSelectorFromString(name);

Return the method name as a String

NSString method = NSStringFromSelector(mySelector);

Verify what an Object has Implemented in Runtime

Determine if an object implement a method

if ( [myObj respondsToSelector:@selector(method1:)] ) {
    [myObj method1];
}

Invoke a method in runtime

Use selector to run a method in runtime

[obj performSelector:@selector(method1:)
    withObject:value];

Equivalent to:

[obj method1:value];