我有一个继承自NSObject的类.它使用NSMutableArray来保存子对象,例如使用NSMutableArray*项的People来保存Person对象.如何在项目上实现NSFastEnumerator?
我尝试过以下但是无效:
@interface People : NSObject <NSFastEnumeration>
{
NSMutableArray *items;
}
Run Code Online (Sandbox Code Playgroud)
@implementation ...
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
{
if(state->state == 0)
{
state->mutationsPtr = (unsigned long *)self;
state->itemsPtr = items;
state->state = [items count];
return count;
}
else
return 0;
}
Run Code Online (Sandbox Code Playgroud) objective-c ×1