Nat! bio photo


Senior Mull

Twitter Github Twitch

The isa pointer, killed by Apple - resurrected by mulle-objc ?

What was isa in Objective-C ?

Technically all Objective-C objects used to look like this before ObjC 2.0:

struct objc_object
   struct objc_class  *isa;

So every code could get to its class quickly just by accessing self->isa or isa for short. It could also change its class, by writing a different class into isa.

Quick in two ways.

First, its much faster to type isa and more importantly faster to read than [self class] or object_getClass( self). Second, after the advent of tagged pointers, the code to retrieve an objects class has become much more complicated, since there may not exist an isa pointer at all anymore. isa was also much faster than the now common [self class].

isa was a well established concept but unfortunately this concept is now eroded, and I bet most programmers don’t even know about it anymore.


isa as a #define

#define isa   object_getClass( self)
  • cheap and easy, but limited
  • &isa and other operations produce undesired and incompatible results
  • isa = [self class] produces a compile error

isa as an Objective-C keyword

Make isa a new keyword in the Objective-C language:

  • adding stuff to clang (C++) is unpleasant
  • bloats the Objective-C language, where isa was more or less a side-effect
  • would produce proper error messages on wrong use (e.g. isa + 1)
  • could support both object_getClass and object_setClass

Use Self as a new Objective-C keyword

In the Objective-C runtimes there are two values defined nil and Nil. Nil is for classes. Following this scheme, one could use Self instead of isa to introduce a “new” concept.

  • mistypes of nil and Nil are inconsequential but self vs Self can be fatal


I’ll likely put the #define isa into objc-compat. That way isa in readonly mode can be used across all participating platforms.

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

E-mail: (not published)