How is known to support FE protocol, I must implement method:
– countByEnumeratingWithState:objects:count:
But it method is do not knows what type of object I want enumerate. For example my custom object has two arrays:
NSArray* names - for NSString objects;
NSArray* sites - for NSURL objects;
Now I want enumerate them:
for( NSString* name in myObj )
{
}
and
for( NSURL* url in myObj )
{
}
Can I do that – countByEnumeratingWithState:objects:count: define what kind of objects it must enumerate? (Without using additional class attributes 🙂 )
No. Fast enumeration can only support one type of enumeration per class so you would have to decide which case is more important for you.
However,
NSEnumeratoralso supports fast enumeration. So your class could support 2 different enumerators (let’s call themnameEnumeratorandurlEnumerator) and the class’s users can then use fast enumeration like this: