Runtime functions
1. You can obtain run-time information or execute some messages dynamically through some of the NSObject methods:
1./*returns a Boolean value that indicates whether the receiving class was a subclass of, or identical to, a given class.*/
1.+ (BOOL) Issubclassofclass: (Class) AClass;
1./*returns a Boolean value that indicates whether instances of the receiver is capable of responding to a given selector .*/
1.+ (BOOL) Instancesrespondtoselector: (SEL) Aselector;
For example: if ([[[Retangle class] Respondstoselector: @selector (print)]==yes) {...}
/*returns a Boolean value that indicates whether the receiver was an instance of a given class.*/
-(BOOL) Ismemberofclass: (Class) AClass; For example: [obj Ismemberofclass:[retangle class]];
In addition to this: Conformstoprotocol checks to see if the object implements the method that specifies the protocol class Methodforselector returns the address Performselector:withobject the specified method implementation method that the SEL refers to
-(ID) Performselector: (SEL) Aselector; -(ID) Performselector: (SEL) Aselector withobject: (ID) object; -(ID) Performselector: (SEL) Aselector withobject: (ID) object1 withobject: (ID) object2; These three methods, which are synchronous execution, are thread-independent and can be called successfully in both the main thread and the child's path. is equivalent to calling the method directly. Use when you need to invoke the method dynamically. For example: [Self performselector: @selector (test2)] and [self test2], execution effect is identical.
-(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) Delay Inmodes: (NSArray *) modes; -(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay; These two methods are executed asynchronously, even if the delay parameter is 0, which is still executed asynchronously. Can only be executed in the main thread, and will not be transferred to the Aselector method in the child thread. Can be used when clicking a button in the UI triggers an event that consumes system performance, the button will remain highlighted during event execution, and the method can be called to handle the event asynchronously to avoid the above problem. Before the method is executed, the cancellation method is:
+ (void) Cancelpreviousperformrequestswithtarget: (ID) atarget selector: (SEL) Aselector object: (ID) anargument; + (void) Cancelpreviousperformrequestswithtarget: (ID) atarget; Note: Call the Cancel function before calling the method or at the end of the Viewcontroller life cycle where the method resides to ensure that no memory leaks are caused.
-(void) Performselectoronmainthread: (SEL) Aselector withobject: (ID) arg waituntildone: (BOOL) Wait modes: (Nsarray *) Array -(void) Performselectoronmainthread: (SEL) Aselector withobject: (ID) arg waituntildone: (BOOL) wait; Both of these methods, which can be executed both in the main thread and in the child thread, invoke the Aselector method of the main thread if wait passes yes, it is executed asynchronously, or synchronous if wait passes No.
Note: Apple does not allow programmers to manipulate the UI in threads other than the main thread, at which point we must call the Performselectoronmainthread function to complete the UI update in the main thread
-(void) Performselector: (SEL) aselector onthread: (Nsthread *) THR Withobject: (ID) arg waituntildone: (BOOL) wait modes: ( Nsarray *) array; -(void) Performselector: (SEL) aselector onthread: (Nsthread *) THR Withobject: (ID) arg waituntildone: (BOOL) wait; Invokes a method in the specified thread. The analysis effect is the same as 3.
-(void) Performselectorinbackground: (SEL) Aselector withobject: (ID) arg driver thread runs in the background
iOS development--Common runtime functions