Internal structure of the iOS class

Source: Internet
Author: User

1. Definition of Class and Object

/a opaque type that represents an Objective-c class.typedef struct objc_class *class;
// represents an instance of a class.struct objc_Object { Class Isa; };/ A pointer to an instance of a class.typedef struct objc_object *id;

The class is a pointer to the Objc_class struct, and the ID is a pointer to the Objc_object struct, whose member Isa is a pointer to the Objec_class struct body.

2. Definition of Objc_class

struct objc_class { Class Isa; //point to Metaclass          class Super_class ; //point to its parent class Const char *name ; //class name Long version ; //class version information, initialization defaults to 0, can be modified by the runtime function class_setversion and class_getversion, read
long info; ///Some identifying information, such as Cls_class (0X1L), indicates that the class is a normal class which contains object methods and member variables ; Cls_meta (0x2l) indicates that the class is Metaclass, which contains class methods ; Long instance_size ; //The instance variable size of the class (including instance variables inherited from the parent class); struct objc_ivar_list *ivars; //address for storing each member variable struct objc_method_list **methodlists ; //related to some flag bits of info, Such ascls_class (0x1l), the method of storing objects, such as Cls_meta (0x2l), is the storage class method ; struct objc_cache *cache; //Pointer to the nearest method used to improve efficiency; struct objc_protocol_list *protocols; //Storage of the agreements to which such class complies     }The class structure pointed to by the ISA pointer in Isa:objec_object (object) is called Class (that is, the class to which the object belongs), which holds the normal member variable and the method of the object method ("-"), but here the class structure pointed to by the ISA pointer is called Metaclass, A method that holds a member variable of type static and a method of static type ("+").

Super_class: A pointer to the parent class of the class, and if the class is a root class (such as NSObject or Nsproxy), then Super_class is null.

<textarea class="crayon-plain print-no" style="-moz-tab-size: 4; font-size: 12px ! important; line-height: 15px ! important; opacity: 0; z-index: 0; overflow: hidden;" readonly="" data-settings="dblclick">can be modified by the runtime function class_setversion and class_getversion, read long info,//Some identification information, such as Cls_class (0x1l) means that the class is normal class, </c 3 ></textarea>

Internal structure of the iOS class

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.