Borkware Miniblog

July 15, 2010

QFF: id and NSFastEnumeration

Filed under: programming, Questions From Friends — Mark Dalrymple @ 2:48 pm

Do I remember correctly that id is a pointer, like a void*?

Yep. It’s a pointer to an objective-C object, but not necessarily an NSObject.

So, id* is a pointer to a pointer?

Yep. Like a void**.

I’m looking at the fast enumeration protocol

I was wondering where this was coming from :-)

- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *) state
                                   objects: (id *) stackbuf
                                     count: (NSUInteger) len;

So it’s expecting you to return an array of object pointers?

If you want. When this method gets called, objects will already be a buffer (presumably on the caller’s stack) that will hold len pointers. You can fill this with your data structure’s contents to be iterated over. You can also return a pointer to your own storage via the state structure’s itemsPtr:

typedef struct {
    unsigned long state;
    id *itemsPtr;
    unsigned long *mutationsPtr;
    unsigned long extra[5];
} NSFastEnumerationState;


  1. I get (historically) why we use “id” instead of “id*”, but man it bugs me sometime.

    Comment by Joel Bernstein — July 15, 2010 @ 2:56 pm

  2. Monsters from the Id.

    Comment by Mark Dalrymple — July 15, 2010 @ 3:01 pm

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: