I have an NSOperation
subclass that runs async operations from a UITableView
.
I override the correct start and finish methods like this:
- (void)start
{
[self willChangeValueForKey:@"isExecuting"];
self.isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
if (self.isCancelled)
{
[self finish];
return;
}
}
- (void)finish
{
if (!_isExecuting)
{
[self willChangeValueForKey:@"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
}
[self willChangeValueForKey:@"isExecuting"];
[self willChangeValueForKey:@"isFinished"];
_isExecuting = NO;
_isFinished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
}
The problem I have, it if I scroll down the table and delete a row, this calls the cancel
method on the operation, however as the operations gradually complete and it reaches further down the table, it crashes with an EXC_BAD_ACCESS
error on the line [self didChangeValueForKey:@"isFinished"];
The code is pretty complex to paste it all here, but what i'd like to know is how can I track down what object is causing the KVO message to crash?
If I enable zombie objects in the debugger, it simply doesn't crash at all with no warnings which doesn't help.
If I wrap the KVO methods in try/catch
it is never caught and still crashes.
I have tried overriding the KVO methods in my NSOperation
subclass, but they are never called:
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
{
NSLog(@"%s - %@", __PRETTY_FUNCTION__, observer);
[super addObserver:observer forKeyPath:keyPath options:options context:context];
}
Is it possible to see who the observers are?