This is an excerpt from Objective-C runtime programming guide
:
When a new object is created, memory for it is allocated, and its instance variables are initialized. First among the object’s variables is a pointer to its class structure. This pointer, called isa, gives the object access to its class and, through the class, to all the classes it inherits from.
isa is declared in NSObject
like this:
Class isa;
In its turn Class
is nothing more than a pointer to the struct
typedef struct objc_class *Class;
And now let's look at this structure:
struct objc_class {
Class isa;
#if !__OBJC2__
Class super_class OBJC2_UNAVAILABLE;
const char *name OBJC2_UNAVAILABLE;
long version OBJC2_UNAVAILABLE;
long info OBJC2_UNAVAILABLE;
long instance_size OBJC2_UNAVAILABLE;
struct objc_ivar_list *ivars OBJC2_UNAVAILABLE;
struct objc_method_list **methodLists OBJC2_UNAVAILABLE;
struct objc_cache *cache OBJC2_UNAVAILABLE;
struct objc_protocol_list *protocols OBJC2_UNAVAILABLE;
#endif
}
We can see that the pointer to the super class (as well as all the rest of the struct's members except another one isa) is unavailable in the latest version of Objective-C.
So my question is how an object can get access to its superclass if super_class
pointer is not available? Does it get access to the superclass through this another one isa pointer? But how exactly it happens? How it works? Can anyone explain it?