NSObject is the base class in OC, all classes inherit from this, which also gives us a lot of methods related to "class" and "method", this article will explain a few very useful methods.
Text:
Person.h
#import <Foundation/Foundation.h> @interface person:nsobject @end </span>
Student.h
#import "Person.h"//Inherit person class @interface Student:person-(void) test1; -(void) Test2: (NSString *) string; @end </span>
MyProtocol.h
#import <Foundation/Foundation.h> @protocol myprotocol @end </span>
"1" infers whether student is an object of the person class
-(BOOL) Ismemberofclass: (Class) AClass; [Student Ismemberofclass:[person class]];
"2" infers whether student is an object of the person class or subclass
-(BOOL) Iskindofclass: (Class) AClass; [Student Iskindofclass:[person class]];
"3" infers whether student follows the MyProtocol protocol (and can also invoke the class to infer if the class follows)
-(BOOL) Conformstoprotocol: (Protocol *) Aprotocol; [Student Conformstoprotocol: @protocol (MyProtocol)]; Or use the class method //+ (BOOL) Conformstoprotocol: (Protocol *) Protocol; [Student Conformstoprotocol: @protocol (MyProtocol)];
"4" infers whether the Test1 method of the student responds (that is, whether the Test1 method is declared and implemented)
-(BOOL) Respondstoselector: (SEL) aselector; [Student Respondstoselector: @selector (test1)];
"5" indirect call to Student's Test1 method (test1 no parameters)
-(ID) Performselector: (SEL) aselector; [Student Performselector: @selector (test1)];
the "6" indirectly calls the Test2 method of student (Test2 has a number of parameters)
-(ID) Performselector: (SEL) Aselector withobject: (ID) object; [Student Performselector: @selector (test2:) withobject:@ "123"]; With a maximum of two parameters //-(ID) performselector: (SEL) Aselector withobject: (ID) object1 withobject: (ID) object2;
"7" Delay 2s call test1 method of student
(There is no delay effect on the command line, since the command line has finished running out of the main function, the iOS part of the main function has been running.) So you can see the delay effect)
<span style= "Font-family:simhei;" >//-(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay; Delay unit is (seconds) [student Performselector: @selector (test2:) withobject:@ "123" afterdelay:2];</span>
Introduction to the "iOS Development series" NSObject method