NSOperationQueue not working in IOS5

假装没事ソ 提交于 2019-12-03 08:11:25

I had this same problem when building against iOS 5. I ended up creating a flag named operationStarted that was NO by default and I toggled to YES when the start method was called. Then in my finish method (where I generate the KVO notifications), I checked the value of the flag before firing the notifications.

The flag definition looks like this:

@property (nonatomic, assign, getter=isOperationStarted) BOOL operationStarted;

The start method:

- (void)start {
    [self setOperationStarted:YES];
    ...
}

My finish method which is called when the operation is complete or cancelled:

- (void)finish {    
    if (![self isOperationStarted]) return;

    [self willChangeValueForKey:@"isExecuting"];
    executing = NO;
    [self didChangeValueForKey:@"isExecuting"];

    [self willChangeValueForKey:@"isFinished"];
    finished = YES;
    [self didChangeValueForKey:@"isFinished"];
}

That ended up resolving the issue for me. Hope it helps someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!