0

如何枚举从数组中心开始的数组?

4

1 回答 1

-2
@implementation NSArray (Extensions)

- (void)enumerateFromCenterGoBothWaysUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
{
    NSMutableArray *copy = [self mutableCopy];
    BOOL shouldStop = NO;
    while([copy count] > 0 && shouldStop == NO)
    {
        NSUInteger index = [copy count] / 2;
        id obj = copy[index];
        [copy removeObject:obj];

        block(obj, index, &shouldStop);
    }
}

@end
于 2013-01-16T09:05:04.387 回答