You can use some NSObject methods to obtain the runtime information or dynamically execute some messages:
/*Returns a Boolean value that indicates whether the receiving class is a subclass of, or identical to, a given class.*/
+ (BOOL)isSubclassOfClass:(Class)aClass;
/*Returns a Boolean value that indicates whether instances of the receiver are capable of responding to a given selector.*/
+ (BOOL)instancesRespondToSelector:(SEL)aSelector;
For example: if ([[Retangle class] respondsToSelector: @ selector (print)] = YES ){......}
/* Returns a Boolean value that indicates whether the specified er is an instance of a given class .*/
-(BOOL) isMemberOfClass :( Class) aClass; for example: [obj isMemberOfClass: [Retangle class];
In addition, conformsToProtocol checks whether the object implements the method methodForSelector of the specified Protocol Class and returns the address performSelector: withObject the method referred to by executing SEL.
-(Id) specify mselector :( SEL) aSelector;-(id) specify mselector :( SEL) aSelector withObject :( id) object;-(id) specify mselector :( SEL) aSelector withObject :( id) object1 withObject :( id) object2; all three methods are executed synchronously and have nothing to do with the thread. The main thread and sub-thread can be called successfully. It is equivalent to directly calling this method. It is used when a method needs to be called dynamically. For example, [self defined mselector: @ selector (test2)] and [self test2]; The execution effect is identical.
-(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( optional) delay inModes :( NSArray *) modes;-(void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay; the two methods are asynchronous execution, even if the parameter passed by delay is 0, it is still asynchronous execution. It can only be executed in the main thread and will not be transferred to the aSelector method in the Child thread. It can be used to trigger an event that consumes system performance when you click a button in the UI. During the event execution, the button is always highlighted. In this case, you can call this method to process the event asynchronously, the above problems can be avoided. Before the method execution time is reached, the cancellation method is:
+ (Void) cancelPreviousPerformRequestsWithTarget :( id) aTarget selector :( SEL) aSelector object :( id) anArgument; + (void) cancelPreviousPerformRequestsWithTarget :( id) aTarget; note: call the cancel function before the method is called or when the viewController lifecycle of the method ends to prevent memory leakage.
-(Void) specified mselecw.mainthread :( SEL) aSelector withObject :( id) arg waitUntilDone :( BOOL) wait modes :( NSArray *) array;-(void) specified mselecw.mainthread :( SEL) aSelector withObject :( id) arg waitUntilDone :( BOOL) wait; both methods can be executed in both the main thread and sub-thread. Both methods call the aSelector method of the main thread. If YES is passed to wait, the method is asynchronously executed, if NO is passed by wait, the task is synchronized.
Note: apple does not allow programmers to operate the ui in a thread other than the main thread. At this time, we must call the javasmselecdomainmainthread function to update the UI in the main thread.
-(Void) implements mselector :( SEL) aSelector onThread :( NSThread *) thr withObject :( id) arg waitUntilDone :( BOOL) wait modes :( NSArray *) array;-(void) implements mselector :( SEL) aSelector onThread :( NSThread *) thr withObject :( id) arg waitUntilDone :( BOOL) wait; call a method in the specified thread. The analysis result is the same as 3.
-(Void) mselectorinbackground :( SEL) aSelector withObject :( id) arg subthread runs in the background