Self and super in the Objective-c

Source: Internet
Author: User
Tags list of attributes

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.