Skip navigation.
 
mlImplementing fast enumeration
FROM : Ben
DATE : Fri May 02 10:41:54 2008

I have been reading the documentation for implementing the 
NSFastEnumeration protocol and am having some difficulties following it.

For completeness, here is the protocol method:
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState 
*)state objects:(id *)stackbuf count:(NSUInteger)len;

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

I have a C array where the elements within it can be converted into 
multiple objects. Say I have 5 objects. Do I provide them all in one 
go and return the total number? Or just one per call and return the 
number remaining?

Also, should the objects be returned by reference in the stackbuf 
variable, or in the itemsPtr field of the state structure?

Apologies if these are basic questions, but I got decidedly lost 
trying to follow the docs.

Ben.

Related mailsAuthorDate
mlImplementing fast enumeration Ben May 2, 10:41
mlImplementing fast enumeration Ben May 2, 21:18
mlRe: Implementing fast enumeration Jens Alfke May 3, 03:12
mlRe: Implementing fast enumeration Adam R. Maxwell May 3, 03:43
mlRe: Implementing fast enumeration Thomas Backman May 3, 15:10
mlRe: Implementing fast enumeration Ben May 3, 19:08