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 に答える