Basics:
Introspection is the inherent capability of objects. When running a program, objects can reveal their basic features based on requests.
You can send a message to an object to ask its own related questions. The object will provide you with an answer when the objective-C runs.
Introspection is an important coding tool that can make programs more efficient and robust.
All objects that inherit nsobjec have the following three methods:"
Iskindofclass: returns whether an object is that kind of class (inheritance defined DED)
Ismemberofclass: returns whether an object is that kind of class (no inheritance)
Respondstoselector: returns whether an object responds to a given Method
The parameter value of method 1 is [nsstring class], which is obtained by sending a class method named class to a class. For example:
If ([OBJ iskindofclass: [nsstring class]) {
Nsstring * s = [(nsstring *) OBJ stringbyappendingstring: @ "Xyzzy"];
}
The parameter value of method 3 is a selector, for example, @ selector (shoot ).
If the shoot method exists in the object, the response is true. For example:
If ([OBJ respondstoselector: @ selector (shoot)]) {
[OBJ shoot];
} Else if ([OBJ respondstoselector: @ selector (shootat :)]) {
[OBJ shootat: Target];
}
Describes a new type of Sel, which is the type of the Selector Used by objective-C.
Sel shootselector = @ selector (shoot );
Sel shootatselector = @ selector (shootat :);
Sel movetoselector = @ selector (moveTo: withpencolor :);
In the nsobject class, you can use the performselector method or the performselector: withobject: Method to execute the selector. For example:
[OBJ into mselector: shootselector];
[OBJ ready mselector: shootatselector withobject: coordinate];
In the nsarray class, you can use makeobjectsperformselector: to perform the selector operation. For example:
[Array makeobjectsperformselector: shootselector]; // cool, huh?
[Array makeobjectsperformselector: shootatselector withobject: Target]; // target is an ID
In the uibutton class, you can use the-(void) addtarget :( ID) anobject action :( SEL) action...; Method to execute the selector. For example:
[Button addtarget: Self action: @ selector (digitpressed :)...];
Content from:
Http://mikixiyou.iteye.com/blog/1587051
Advanced:
Runtime of objective-C
Http://blog.sina.com.cn/s/blog_4cd8dd130101juf1.html
Http://www.linuxidc.com/Linux/2012-02/54989.htm
Http://www.cocoachina.com/macdev/objc/2013/0115/5541.html