Created
February 1, 2012 01:45
-
-
Save jnjosh/1714446 to your computer and use it in GitHub Desktop.
A painfully simple and probably incomplete NSDictionary Subtraction method
This file contains hidden or 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
@interface NSDictionary (Subtraction) | |
- (NSDictionary *)subtractDictionary:(NSDictionary *)dictionary; | |
@end |
This file contains hidden or 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 NSDictionary (Subtraction) | |
- (NSDictionary *)subtractDictionary:(NSDictionary *)dictionary { | |
NSMutableDictionary *differenceDictionary = [NSMutableDictionary dictionary]; | |
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
if (! [dictionary objectForKey:key]) [differenceDictionary setObject:obj forKey:key]; | |
}]; | |
return differenceDictionary; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment