25#import <Foundation/Foundation.h>
28@implementation NSMutableDictionary (OOExtensions)
30- (void)mergeEntriesFromDictionary:(NSDictionary *)otherDictionary
32 NSEnumerator *otherKeysEnum =
nil;
35 for (otherKeysEnum = [otherDictionary keyEnumerator]; (key = [otherKeysEnum nextObject]); )
37 if (![
self objectForKey:key])
38 [
self setObject:[otherDictionary objectForKey:key] forKey:key];
42 id thisObject = [
self objectForKey:key];
43 id otherObject = [otherDictionary objectForKey:key];
45 if ([thisObject isKindOfClass:[NSDictionary
class]]&&[otherObject isKindOfClass:[NSDictionary
class]]&&(![thisObject isEqual:otherObject]))
47 NSMutableDictionary* mergeObject = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary*)thisObject];
48 [mergeObject mergeEntriesFromDictionary:(NSDictionary*)otherObject];
49 [
self setObject:mergeObject forKey:key];
53 if ([thisObject isKindOfClass:[NSArray
class]]&&[otherObject isKindOfClass:[NSArray
class]]&&(![thisObject isEqual:otherObject]))
55 NSMutableArray* mergeObject = [NSMutableArray arrayWithArray:(NSArray*)thisObject];
56 [mergeObject addObjectsFromArray:(NSArray*)otherObject];
57 [
self setObject:mergeObject forKey:key];
62 [
self setObject:otherObject forKey:key];