From this reference:
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.
From what I could understand reading this and this, it allows, for one, to use introspection but in a pragmatic way (iOS development), what can a programmer benefit from knowing/understanding this special pointer?
The real benefit is a better understanding of the Objective-C runtime, which is actually quite complex compared to static languages like C++. The isa
pointer, in practical terms, isn't really used all that much unless you're hacking the runtime to do something special. This guide has more info on how it is used by the runtime.
You shouldn't really use the isa
directly in production code. It's like retainCount
- it's important you understand it but you shouldn't ever call it.
On 64-bit environment, an object’s isa
field shouldn’t be accessed. The isa
field no longer holds a pointer. It includes some pointer data and uses the remaining bits to hold other runtime information. class
property or object_getClass()
function can be used to read an isa
field. object_setClass()
can be used to write an isa
field. By the way, if isa
is set, [obj class]
might be different with object_getClass()
such as KVO observed object.
Ref: https://developer.apple.com/documentation/uikit/app_and_environment/updating_your_app_from_32-bit_to_64-bit_architecture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With