Skip to content

Instantly share code, notes, and snippets.

@MartinJNash
Last active December 22, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinJNash/16767f10b8641c0982ed to your computer and use it in GitHub Desktop.
Save MartinJNash/16767f10b8641c0982ed to your computer and use it in GitHub Desktop.
// .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