I want to store array of custom object. So I have tried encode and decode. but its not working
Please check my code.
- (IBAction)saveFile{
NSLog(@"%@",self.drawingView.pathArray);
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:self.drawingView];
[arrayData writeToFile:[DOCUMENTPATH stringByAppendingPathComponent:@"1.plist"] atomically:YES];
}
Console O/P
(
"<ACEDrawingPenTool: 0x8b48d80;>",
"<ACEDrawingPenTool: 0xa225530;>"
)
Now I m encoding array with this
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:self.pathArray forKey:@"array"];
}
After this when I try to get object
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.pathArray = [aDecoder decodeObjectForKey:@"array"];
NSLog(@"%@",self.pathArray); // returns nil
[self configure];
}
return self;
}
decodeObjectForKey returns nil