MiguelC
MiguelC

Reputation: 308

Where exactly is the isa pointer implemented in objects?

I read that the isa pointer looks for the instance method in a message to check if there really is that method in classes and their superclasses. So my question is, where is it implemented in objects?

Upvotes: 0

Views: 442

Answers (2)

MrMage
MrMage

Reputation: 7487

Note that you should not access the isa pointer directly to get an objects class but use objc_getClass() instead. In ARM64, for example, the isa field contains other flags (most notably the object's reference count if it is sufficiently small) in addition to the class pointer. See this post by Mike Ash for more details.

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

If you look in the runtime for a class you'll come across this...

typedef struct objc_class *Class;
typedef struct objc_object {
    Class isa;
} *id; 

Edit:

Also in NSObject.h

/***********    Base class      ***********/

NS_ROOT_CLASS
@interface NSObject <NSObject> {
    Class   isa;
}

Upvotes: 0

Related Questions