Reputation: 40329
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?
Upvotes: 3
Views: 3046
Reputation: 78343
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.
Upvotes: 6
Reputation: 351476
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 isa
comes from the OOP concept of IS-A
which is simply a relationship between two objects like this:
A dog IS-A mammal.
A car IS-A vehicle.
So the isa
instance variable can be helpful in that it can tell you what IS-A
relationships your class has in its inheritance hierarchy.
Upvotes: 7