Last active
December 22, 2015 00:49
-
-
Save MartinJNash/16767f10b8641c0982ed 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
// .h | |
@interface NSMutableDictionary (NilHandlingDictionary) | |
-(void)MJNInsertNullIfNilObject:(id)value forKey:(id<NSCopying>)key; | |
-(void)MJNDoNothingIfNilObject:(id)value forKey:(id<NSCopying>)key; | |
@end | |
// .m | |
@implementation NSMutableDictionary (NilHandlingDictionary) | |
-(void)MJNInsertNullIfNilObject:(id)value forKey:(id<NSCopying>)key | |
{ | |
if (!value) { | |
self[key] = [NSNull null]; | |
return; | |
} | |
self[key] = value; | |
} | |
-(void)MJNDoNothingIfNilObject:(id)value forKey:(id<NSCopying>)key | |
{ | |
if (!value) { | |
return; | |
} | |
self[key] = value; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment