diff --git a/ChangeLog b/ChangeLog index 4a3bddec2..32672fa19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-06-14 Richard Frith-Macdonald + + * Source/NSDictionary.m: MacOS-X compatibility fix for keyed encoding + of empty dictionary. + 2004-06-10 Adam Fedor * Version 1.9.2 diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index f31f0bf08..e9c5b557e 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -182,41 +182,38 @@ static SEL appSel; if ([aCoder allowsKeyedCoding]) { - if (count > 0) + id key; + unsigned i; + + if ([aCoder class] == [NSKeyedArchiver class]) + { + NSArray *keys = [self allKeys]; + id objects = [NSMutableArray arrayWithCapacity: count]; + + for (i = 0; i < count; i++) + { + key = [keys objectAtIndex: i]; + [objects addObject: [self objectForKey: key]]; + } + [(NSKeyedArchiver*)aCoder _encodeArrayOfObjects: keys + forKey: @"NS.keys"]; + [(NSKeyedArchiver*)aCoder _encodeArrayOfObjects: objects + forKey: @"NS.objects"]; + } + else if (count > 0) { NSEnumerator *enumerator = [self keyEnumerator]; - id key; - if ([aCoder class] == [NSKeyedArchiver class]) + i = 0; + while ((key = [enumerator nextObject]) != nil) { - NSArray *keys = [self allKeys]; - id objects = [NSMutableArray arrayWithCapacity: count]; - unsigned i; + NSString *s; - for (i = 0; i < count; i++) - { - key = [keys objectAtIndex: i]; - [objects addObject: [self objectForKey: key]]; - } - [(NSKeyedArchiver*)aCoder _encodeArrayOfObjects: keys - forKey: @"NS.keys"]; - [(NSKeyedArchiver*)aCoder _encodeArrayOfObjects: objects - forKey: @"NS.objects"]; - } - else - { - unsigned i = 0; - - while ((key = [enumerator nextObject]) != nil) - { - NSString *s; - - s = [NSString stringWithFormat: @"NS.key.%u", i]; - [aCoder encodeObject: key forKey: s]; - s = [NSString stringWithFormat: @"NS.object.%u", i]; - [aCoder encodeObject: [self objectForKey: key] forKey: s]; - i++; - } + s = [NSString stringWithFormat: @"NS.key.%u", i]; + [aCoder encodeObject: key forKey: s]; + s = [NSString stringWithFormat: @"NS.object.%u", i]; + [aCoder encodeObject: [self objectForKey: key] forKey: s]; + i++; } } }