Re: Implementing NSFastEnumeration

Gerd Knops <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Oct 1, 2009, at 11:30 AM, Christiaan Hofman wrote:
>
[..]

> While this works for small arrays, for larger arrays this gives a  
> memory access crasher. The reason seems to be that NSArray can  
> return more items than len (the size of stackbuf) in a single call.
>
Correct. The trick is to use a variable in the state to note you  
count. state->state happens to be 0 when first called, and OS X will  
not touch it. So you can use it to remember where you were at for the  
next call. See my example code.

> And another question I have been unable to find an answer to in the  
> docs. Foundation collections are implemented as class clusters. So  
> is NSFastEnumeration implemented as a primitive or a derived method?  
> In other words: when I subclass NSArray (or another collection  
> class), does it already have a default implementation of  
> NSFastEnumeration, or am I forced to always implement it when I want  
> to use for(...in...)?
>
AFAIK subclassing class clusters doesn't work, which is why I think  
they are a poor design.

Gerd
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.