According the Objective-C runtime reference:
ivar_getOffset
Returns the offset of
an instance variable.ptrdiff_t ivar_getOffset(Ivar ivar)
Discussion For instance variables of
type id or other object types, call
object_getIvar and object_setIvar
instead of using this offset to access
the instance variable data directly.Declared In runtime.h
Why is this? What does object_getIvar do to object types?
EDIT: changed question from subscripting (void *) to (id *).
There is no difference between those two approaches when it comes to getting the value of the ivar. You can verify this by looking at
object_getIvar()‘s implementation in Apple’s open-source Obj-C runtime code.object_setIvar()does more than just assign to an offset from the object pointer. It is careful to call through to the garbage-collection runtime functionobjc_assign_ivar()to perform the actual assignment.More magic might be added to either of these functions in future; in general, you should use the highest-level API available at any given time.