Search code examples
objective-cfast-enumeration

Example of adopting/implementing fast enumeration for my class?


I'm trying to understand how to adopt the fast enumeration protocol (under iOS/objective C) for a class I'm creating. I read the section of Apple's docs, but... I don't quite get it!

Anyone have some sample code I could look at?

What I'm trying to do: I have an array of objects over which I want a sender to iterate. The sender wants to use a for-in construct. The catch is I don't want the sender to see all the objects in the array because some of them aren't valid in the context of the application.

In other words, I want my iterator to return a subset of objects in the array matching certain criteria.

I'd prefer not to create any new arrays in the process so as not to slow things down.


Solution

  • Apple's own FastEnumerationSample demonstrates it quite well. From the sounds of it, you may not have seen it yet.

    There's also this blog post.