Skip to content

Instantly share code, notes, and snippets.

@jnjosh
Created February 1, 2012 01:45
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 jnjosh/1714446 to your computer and use it in GitHub Desktop.
Save jnjosh/1714446 to your computer and use it in GitHub Desktop.
A painfully simple and probably incomplete NSDictionary Subtraction method
@interface NSDictionary (Subtraction)
- (NSDictionary *)subtractDictionary:(NSDictionary *)dictionary;
@end
@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