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;
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
Monsters from the Id.
Comment by Mark Dalrymple — July 15, 2010 @ 3:01 pm