In the NSObject Class Reference they talk about an "isa instance variable" which
is initialized to a data structure that describes the class
can someone explain what I should know about this isa instance variable? What is that good for? What does isa mean? Sounds like a norm, like DIN, ISO, etc.; Any idea what that is?
-
It is used to determine a class's inheritance path. More formally:
When a new object is created, it is allocated memory space and its data in the form of its instance variables are initialised. Every object has at least one instance variable (inherited from NSObject) called isa, which is initialized to refer to the object's class. Through this reference, access is also afforded to classes in the object's inheritance path. - Objective-C GNUstep Base Programming Manual: Objective-C
The name
isacomes from the OOP concept ofIS-Awhich is simply a relationship between two objects like this:A dog IS-A mammal.
A car IS-A vehicle.So the
isainstance variable can be helpful in that it can tell you whatIS-Arelationships your class has in its inheritance hierarchy. -
It's basically the pointer to the object's class and is what the Objective-C runtime is based around. The runtime uses it to get an objects method dispatch table and anything else that's stored on the class structure. It's pretty much the only thing that every Objective-C object has to have.
For the most part, you can completely ignore it.
0 comments:
Post a Comment