// // NSArray+NGAAdditions.m // MBMenuExtra // // Created by Michael Bishop on 1/23/10. // Copyright 2010 Perforce Software. All rights reserved. // #import "NSDictionary+NGAAdditions.h" @implementation NSDictionary (NGAAdditions) -(id)dictionaryByRemovingObjectsForKeys:(NSArray*)keys { NSMutableDictionary * dictionary = [NSMutableDictionary dictionaryWithDictionary:self]; [dictionary removeObjectsForKeys:keys]; return [NSDictionary dictionaryWithDictionary:dictionary]; } -(id)dictionaryByRemovingObjectForKey:(id)key { return [self dictionaryByRemovingObjectsForKeys:[NSArray arrayWithObject:key]]; } -(id)objectConvertingNullToNilForKey:(id)aKey { id object = [self objectForKey:aKey]; if ( [[NSNull null] isEqual:object] ) return nil; return object; } @end @implementation NSMutableDictionary (NGAAdditions) -(void)setObjectConvertingNilToNull:(id)object forKey:(NSString*)key; { id realObject = object? object : [NSNull null]; [self setObject:realObject forKey:key]; } -(void)setObjectIgnoringNil:(id)object forKey:(NSString*)key; { if ( !object ) return; [self setObject:object forKey:key]; } -(void)setObjectRecognizingNil:(id)object forKey:(NSString*)key { if ( !object ) [self removeObjectForKey:key]; else [self setObject:object forKey:key]; } -(void)removeAllEntriesWithValuesEqualTo:(id)object { [self removeObjectsForKeys:[self allKeysForObject:object]]; } @end