Dies könnte funktionieren:
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary
Dadurch werden die Schlüssel, aber nicht die Werte, eines NSDictionary
. Natürlich, wenn Sie eine tiefe Kopie benötigen, werfen Sie einen Blick auf diese:
@interface NSDictionary(rross)
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary copyItems:(BOOL) copyItems;
@end
@implementation NSDictionary(rross)
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary copyItems:(BOOL) copyItems
{
if (copyItems)
{
// get the keys
NSArray *oldKeys = [otherDictionary allKeys];
for (int i = 0; i < oldKeys.count; i++)
{
// add all the new key/value pairs
id key = [oldKeys objectAtIndex:i];
[self setObject:[[[otherDictionary objectForKey:key] copy] autorelease] forKey:[[key copy] autorelease]];
}
}
else
{
[self addEntriesFromOtherDictionary:otherDictionary];
}
}
@end