The self and Super 1.self in Objective-c is a hidden parameter, and super is the compiler indicator that 2.self and super point to the same message receiver 3.self call is from the method list of the current class to find the method, if not go to the parent class to find, Until you find the NSObject class. Super will start looking directly from the parent class's method, and if not, go to the parent class to find the method until the NSObject Class 4. The internal principle can be interpreted using the runtime to interpret 4.1 [self class] When invoking the method by Objc_msgse The ND function sends the message ID objc_msgsend (ID thereceiver, SEL theselector, ...) The first parameter of this function is the message receiver (self), and the second is the method (class) to invoke. 4.2 [Super Class] calls the method with the Objc_msgsendsuper function to send the message
id objc_msgSendSuper(
struct
objc_super *super, SEL op, ...)
The first argument is a struct variable, the second is the method (class) that the argument is to call, and then the struct is as follows
struct objc_super { ID receiver; Class superclass;};
The first member is the message receiver (self), which is called the same message receiver as self, and the second is super's parent person. This will begin the lookup of the method, first go to the parent class to find the class method, if not go to the parent class to find, until Nsobjcet Here's how to find a method between classes primarily by the ISA pointer, each object has an Isa pointer, which, by default, points to the class object. A list of object methods, a list of member variables, and a list of attributes are saved in the class object. The list of class methods is saved in the original Class (meta). The relationship between them is as follows: the first class to find is determined by the method type, (object methods go to the object class, the class method goes to the Meta Class), and then go back to NSObject
Self and super in the Objective-c