I have an object observer that I only need to detect one thing. Once I’m done with it, I’d like to remove it to eliminate overhead.
So it would look something like this:
-(void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*) change context:(void*)context{
if ([keyPath isEqual:@"doingSomething"]){
if ([object isDoingSomething] == NO) {
[my_object setDoingSomething: DO_NOTHING_FOREVER];
[my_object removeObserver:self forKeyPath:@"doingSomething"] // <= ERROR eventually
}
}
}
This does not work though and throws an error like:
NSKVOPendingNotificationRelease “EXC_BAD_ACCESS”
Shouldn’t you be calling remove observer on the
object?removeObserver:forKeyPath:method should be called on the receiver.