Closed shobhz closed 7 years ago
Also happens in my project!
Can you make a try-catch around the part where the KVO observer gets removed like this (sorry for objective-c code):
Safe Unsubscribe with @try / @catch
Perhaps the most pronounced annoyance with KVO is how it gets you at the end. If you make a call to –removeObserver:forKeyPath:context: when the object is not registered as an observer (whether because it was already unregistered or not registered in the first place), an exception is thrown. The kicker is that there’s no built-in way to even check if an object is registered!
Which causes one to rely on a rather unfortunate cudgel @try with an unhandled @catch:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
@try {
[object removeObserver:self forKeyPath:NSStringFromSelector(@selector(isFinished))];
}
@catch (NSException * __unused exception) {}
}
}
Good job!
@oonoo It's welcome for you to commit pull request. Let's fix it! : )
I've fixed this ^
removeObserver crashed in ESRefreshComponent - not always but often!
*\ Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <App.ESRefreshHeaderView 0x108b05430> for the key path "contentOffset" from <App.UITableView 0x1030ec200> because it is not registered as an observer.'