Hi,
i am having troubles writing an NSMutableDictionary
List is
in the custom object, I adopt the NSCoding protocol lie this:
in the .h file:
in the implementation file:
I write to file like this:
But it keeps failing. Any idea why?
Thanks.
i am having troubles writing an NSMutableDictionary
List is
Code:
list = [[NSMutableDictionary dictionaryWithCapacity:3500] retain];
// this is how I add custom objects...
[list setObject:newEntry forKey:key];
in the custom object, I adopt the NSCoding protocol lie this:
in the .h file:
Code:
@interface Entry : NSObject <NSCoding> {
in the implementation file:
Code:
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
shape = [[decoder decodeObjectForKey:@"shape"] retain];
sizeIndex = [decoder decodeIntForKey:@"sizeIndex"];
price = [decoder decodeFloatForKey:@"price"];retain];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:shape forKey:@"shape"];
[encoder encodeInt:sizeIndex forKey:@"sizeIndex"];
[encoder encodeFloat:price forKey:@"price"];
}
I write to file like this:
Code:
if ([list writeToFile:filePath atomically:YES]) NSLog(@"success");
else NSLog(@"failed");
But it keeps failing. Any idea why?
Thanks.