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