Search code examples
objective-cfast-enumeration

How do I detect if an object implements NSFastEnumeration protocol in Objective-C?


I want to use fast enumeration on an object of type id.

Basically I'm missing the check here:

id object = <get object form somewhere>;
if( <check if object implements fast enumeration> )
    for (id item in id<NSFastEnumeration>object)
        <process item>

Solution

  • Something like this:

    BOOL canBeFast = [yourCollection conformsToProtocol:@protocol(NSFastEnumeration)];