Re: Implementing NSFastEnumeration

Sherm Pendley <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Thu, Oct 1, 2009 at 9:13 AM, Christiaan Hofman <[email protected]> wrote:
>
> An important question I have is: which variable should eventually hold the
> objects to return? As the NSFastEnumeration doc says that stackbuf is "A C
> array of objects over which the sender is to iterate", which would suggest
> that that's where the objects should be returned. However I saw this blog at
> <http://cocoawithlove.com/2008/05/implementing-countbyenumeratingwithstat.html>
> that has some samples that suggest that the real place to return the objects
> is in state->itemsPtr.

Yes, the real place to return the objects is state->itemsPtr. The
stackbuf argument points to a C array you can fill with your objects
if you're not already using a C array to hold them. You *can* use that
buffer, but you don't have to, and in some situations you probably
won't want to.

The first example above is for classes that already have a C array
that they simply want to return as-is. It simply assigns the existing
array pointer to state->itemsPtr, and ignores the space provided in
stackbuf.

The second example is for classes that don't have an existing C array.
It fills the array pointed to by stackbuf, then assigns stackbuf to
state->itemsPtr.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
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.