-(BOOL) isKindOfClass: classObj is used to determine whether it is an instance of a class or its subclass.
-(BOOL) isMemberOfClass: classObj is used to determine whether it is an instance of a class.
-(BOOL) respondsToSelector: selector is used to determine whether there is a method named after a certain name (encapsulated in a selector object for passing)
+ (BOOL) instancesRespondToSelector: selector is used to determine whether an instance has a method named after a certain name. the difference is that the previous method can be used on instances and classes, and this method can only be used on classes.
-(Id) specify mselector: selector
SEL sel = @ selector (start :); // specify action
If ([obj respondsToSelector: sel])
{// Determine whether the object has a corresponding method
[Obj into mselector: sel withObject: self]; // call the selector Method
}
Use [[UIApplication sharedApplication] keyWindow] to find the main window object of the application
RespondsToSelector determines whether a method is implemented
Tester. h
# Import <Foundation/Foundation. h> @ interface Tester: NSObject {}-(void) test :( NSString *) msg;-(void) noibd; @ end
Tester. m
# Import "Tester. h "@ implementation Tester-(void) test :( NSString *) msg {NSLog (@" % @ ", msg) ;}@ end note: noibd method is not implemented
Main. m
# Import <Foundation/Foundation. h> # import "Tester. h "int main (int argc, const char * argv []) {ngutoreleasepool * pool = [[ngutoreleasepool alloc] init]; id tester = [Tester alloc] init]; // Note: Here id SEL testSelector = @ selector (test :); SEL notImpSelector = @ selector (noibd :); if ([tester respondsToSelector: testSelector]) {// tester. m implements the test method [tester test: @ "invoke test method"];} if ([tester respondsToSelector: notImpSelector]) {// test. m does not implement this master, go to [tester noibd];} [pool drain]; return 0 ;}