The Essence of OC Foundation (10) class and the simple introduction of ISA pointer and Meta class

Source: Internet
Author: User

First, the basic concepts of the class:

1, the class is actually an object, this object will be created when this class is used for the first time

2. As long as you have a class object, you can create an instance object from the class object in the future

3. There is an Isa pointer in the instance object that points to creating your own class object

4. All object methods of the current object are saved in the class object

5. When sending a message to an instance object, the corresponding class object is searched according to the ISA pointer in the instance object.

6. Inheritance of all class objects is the inheritance relationship of meta-class objects

Second, ISA pointer

1. Each object contains an ISA pointer. This pointer points to the class to which the current object belongs.

2.[d bark]; indicates that a bark message is sent to the object to which D points, and the bark method of the object is called, and the object locates the method stored in the class along with the internal ISA pointer and executes.

3.isa is a hidden pointer in the object that points to the class that created the object.

4. Through the ISA pointer we can know at run time that the current object belongs to that class.

Three, meta-class

1, the definition of the meta-class is a Class object class, each class has its own unique meta-class, that is,

(1) When you send a message to an object, the message is a list of methods in the class that is looking for the object.

(2) When you send a message to a class, the message is a list of methods that are looking for the class's meta-class.

A meta-class is necessary because it stores class methods for classes. Each class must have a unique meta-class, because each class has a unique class method.

2, the class of the Meta class:

(1) A meta-class, like a class, is also an object and can call its methods. This means that he must also have a class.

(2) All of the meta-classes use the root class (the meta-class of the class at the top of the inheritance system) as their class. That is, the meta-classes of all NSObject subclasses will use the NSObject as their class.

(3) All meta classes use the root class as their class, and the meta class of the root class is itself. That is to say, the ISA pointer to the base class's meta-class points to himself.

The Essence of OC Foundation (10) class and the simple introduction of ISA pointer and Meta class

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.