Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Safely remove KVO-observer.
@interface NSObject (KVO)
- (void)safelyRemoveObserver:(nonnull NSObject *)observer forKeyPath:(nonnull NSString *)keyPath;
@end
#import "NSObject+KVO.h"
@implementation NSObject (KVO)
- (void)safelyRemoveObserver:(nonnull NSObject *)observer forKeyPath:(nonnull NSString *)keyPath
{
@try {
[self removeObserver:observer forKeyPath:keyPath];
} @catch (NSException * __unused exception) {
// nothing to do
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment