IOS development-Introspective)

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.