Re: Implementing NSFastEnumeration

Tom Hageman <trh-qWit8jRvyhVmR6Xm/[email protected]>
Newsgroups gmane.comp.macosx.devel
Organization Warty Wolfs
Message-ID <[email protected]>
On Fri,  2 Oct 2009 00:21:24 +0200, Tom Hageman wrote:
> How about _replacing_ the key in itemsPtr[i] with the value as you go
> along? Something like this: (Achtung, Mailware!)
>
> - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
> {
> 	NSUInteger i, count = [keys countByEnumeratingWithState:state
> objects:stackbuf count:len];
> 	for (i = 0; i < count; i++)
> 	{
> 		id key = state->itemsPtr[i];
> 		id value = [values objectForKey:key];
> 		state->itemsPtr[i] = value;
> 		//stackbuf[i] = value;
> 	}
> 	//state->itemsPtr = stackbuf;
> 	return count;
> }

Urrgh, what was I thinking?  This is a bad idea, as it may overwrite some  
objects private backingstore.  So don't do this!

--Tom.
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.