문제

Many classes have enumeration functions like this one for NSArray:

- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block

What is the correct way (design pattern) to implement this in your own class? The code below is how I would do it, but that's maybe not the correct way? For argument's sake _contents is an NSArray, but it could be any suitable data structure. Block enumeration is supposed to be faster than fast enumeration. This snippet doesn't seem anything special that would make it faster though.

 - (void)enumerateInputData:(NSRange) range
                      block:(void(^)(NSData *data, NSUInteger index, BOOL *stop)) enumerationBlock
{
    BOOL stop = NO;
    for (NSUInteger index = range.location; index < NSMaxRange(range); index++)
    {
        //custom processing
        NSData *data = [_contents objectAtIndex:index];

        enumerationBlock(data, index,&stop);
        if (stop) {
            break;
        }
    }
}

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top