Created
February 18, 2010 10:48
-
-
Save alexrozanski/307568 to your computer and use it in GitHub Desktop.
NSMutableDictionary category to handle setting nil as an object for a key, adding [NSNull null] instead.
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
#import <Cocoa/Cocoa.h> | |
@interface NSMutableDictionary (PXDictionaryAdditions) | |
- (BOOL)setObjectOrNull:(id)anObject forKey:(id)aKey; | |
@end |
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
#import "NSMutableDictionary+PXDictionaryAdditions.h" | |
@implementation NSMutableDictionary (PXDictionaryAdditions) | |
//Returns NO if `anObject` is nil; can be used by the sender of the message or ignored if it is irrelevant. | |
- (BOOL)setObjectOrNull:(id)anObject forKey:(id)aKey | |
{ | |
if(anObject!=nil) { | |
[self setObject:anObject forKey:aKey]; | |
return YES; | |
} | |
else { | |
[self setObject:[NSNull null] forKey:aKey]; | |
return NO; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment