Created
October 6, 2016 15:13
-
-
Save marty-suzuki/8054a9048a50fa8aa319dcf358cc0832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSObject (Error) | |
- (void)removeObserver:(NSObject * _Nonnull)observer forKeyPath:(NSString * _Nonnull)keyPath error:(NSError * _Nullable __autoreleasing * _Nullable)error { | |
@try { | |
[self removeObserver:observer forKeyPath:keyPath]; | |
} @catch (NSException *exception) { | |
NSMutableDictionary *userInfo = nil; | |
if (exception.userInfo == nil) { | |
userInfo = [NSMutableDictionary dictionaryWithCapacity:0]; | |
} else { | |
userInfo = exception.userInfo.mutableCopy; | |
} | |
userInfo[NSLocalizedDescriptionKey] = exception.reason; | |
*error = [NSError errorWithDomain:exception.name code:-9999 userInfo:userInfo]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment