On 21 Jun 2005, at 17:43, Will Mason wrote: The arrays contain custom class objects. For each of these I have defined initWithCoder methods that use encodeObject:forKey, encodeBool:forKey, etc. calls to archive their data members. The calls to encodeObject:forKey only pass built-in class objects (NSString, NSNumber, NSCalendarDate).
initWithCoder: is for decoding, not for encoding, so calling encodeObject:forKey: in initWithCoder: is not very productive. Have you defined encodeWithCoder: for your custom classes, putting the encodeObject:forKey: in that method?
Oops, naughty fingers not typing what I intended! My classes have methods like this:
- (void) encodeWithCoder:(NSCoder*) inCoder { [super encodeWithCoder:inCoder]; [inCoder encodeBool:mIncome forKey:kIncomeLabel]; [inCoder encodeBool:mExpenditure forKey:kExpenditureLabel]; }
- (id) initWithCoder:(NSCoder*) inCoder { if (self = [super initWithCoder:inCoder]) { [self setIncome:[inCoder decodeBoolForKey:kIncomeLabel]]; [self setExpenditure:[inCoder decodeBoolForKey:kExpenditureLabel]]; } return(self); }
While my document class has:
- (NSData *)dataRepresentationOfType:(NSString *)aType { NSMutableDictionary* theDict = [NSMutableDictionary dictionary]; [theDict setValue:[self categories] forKey:kCategoriesLabel]; [theDict setValue:[self items] forKey:kItemsLabel]; return([NSArchiver archivedDataWithRootObject:theDict]); }
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType { NSDictionary* theDict = [NSUnarchiver unarchiveObjectWithData:data]; [mCategories release]; mCategories = [theDict valueForKey:kCategoriesLabel]; [mCategories retain]; [mItems release]; mItems = [theDict valueForKey:kItemsLabel]; [mItems retain]; return(YES); }
Rev. Andy |