Skip to content

Instantly share code, notes, and snippets.

@StefanLage
Created February 23, 2015 14:07
Show Gist options
  • Save StefanLage/1dcd909907d9b1d53277 to your computer and use it in GitHub Desktop.
Save StefanLage/1dcd909907d9b1d53277 to your computer and use it in GitHub Desktop.
Removes each key/value in another given dictionary from the receiving dictionary, if present.
#import <Foundation/Foundation.h>
@interface NSMutableDictionary (Minus)
-(void) minusDictionary:(NSDictionary*)otherDictionary;
@end
#import "NSMutableDictionary+Minus.h"
@implementation NSMutableDictionary (Minus)
-(void) minusDictionary:(NSDictionary*)otherDictionary{
NSMutableSet *setA = [NSMutableSet setWithArray:self.allKeys];
NSMutableSet *setB = [NSMutableSet setWithArray:otherDictionary.allKeys];
// Get the right keys to remove
[setA intersectSet:setB];
[self removeObjectsForKeys:setA.allObjects];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment