Type of ISA property for IOS NSObject Class

Source: Internet
Author: User

The ISA attribute of the previous to NSObject also know point, but understand not deep, today read this post, feel very good, summarize:

http://chun.tips/blog/2014/11/05/bao-gen-wen-di-objective%5bnil%5dc-runtime-(2)%5Bnil% 5d-object-and-class-and-meta-class/

First put the most important picture on the inside:

We are looking at a few important definitions:

/// An opaque type, represents an Objective-c class. struct objc_class *class; /// represents an instance of a class. struct objc_object {    Class isa  objc_isa_availability;}; /// A pointer to a instance of a class. struct objc_object *ID;

Here is another mention: In fact, the ID is not nsobject *, but the struct objc_object *, then why can the ID point to any NSObject object? Because Objc_object has only one class-type ISA variable, this structure is exactly the same as the NSObject definition:

@interface NSObject <NSObject> {    Class isa  objc_isa_availability;}

In this way, the content at the first address of the NSObject object can be pointed to by the ID. Because essentially, the object's data is stored by the struct.

Look at the definition:

structObjc_class {class Isa objc_isa_availability;#if!__objc2__Class Super_class objc2_unavailable; Const Char*name objc2_unavailable; Longversion objc2_unavailable; Longinfo objc2_unavailable; Longinstance_size objc2_unavailable; structObjc_ivar_list *Ivars objc2_unavailable; structObjc_method_list * *methodlists objc2_unavailable; structObjc_cache *Cache objc2_unavailable; structObjc_protocol_list *protocols objc2_unavailable;#endif} objc2_unavailable;

Although this is not a new version of the definition, but the basic concept of the same. In the OBJC_CLASS structure, there are also 2 pointers to the OBJC_CLASS structure, ISA and super.

When we call the class method of each ordinary object, we return a pointer to the Objc_class struct that corresponds to that class. An object of the same class, calling the class method, returns a pointer to the same objc_class struct body.

The role of Meta class in the diagram is not always understood, why do you need it? Are there any practical applications?

Type of ISA property for IOS NSObject 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.