When you perform a quick enumeration, you do not need to return all elements at once. Of course, all you get if you return them one at a time is a quick enumeration syntax without significant performance benefit.
You can return one element each time countByEnumeratingWithState:objects:count is called, or you can return all elements, or even just N elements.
For example, let's say you have a huge tree. You can use the stack buffer passed to you and its length:
NSUInteger numItemsToReturn = MIN(100, lengthOfStackBuffer);
You can then continue traversing the tree until numItemsToReturn or until you reach the end of your tree.
The internal infrastructure will continue to call countByEnumeratingWithState:objects:count until it sees the correct number of elements.
Please note that if you are only returning a piece of data, you will need to store the information in state so that you know where you can resume it next time. This is for extra .
EDIT
Commented out on the original post ... If you want to support fast enumeration, then this is pretty easy, as mentioned above.
However, if you just want to traverse the tree to do something, you may need to consider the enumeration API. For instance:
-(void)enumerateWithOptions:(MyTreeEnumerationOptions)options usingBlock:^(id object, unsigned int level, BOOL isLeaf, BOOL *stop)block {
Then users could call:
[tree enumerateWithOptions:PreOrderDepthFirst usingBlock:^(id object, unsigned int level, BOOL isLeaf, BOOL *stop) {