I have read many question how to save custom objects but I m not getting a idea. I don't know what to do next thats why I am asking a question.
Save custom object in plist file
NSLog(@"%@",self.drawingView.pathArray);
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:self.drawingView.pathArray];
[arrayData writeToFile:[DOCUMENTPATH stringByAppendingPathComponent:@"1.plist"] atomically:YES];
Console o/p
(
"<PenTool: 0xa031f80;>",
"<PenTool: 0x8b2b360;>",
"<PenTool: 0xa03aca0;>",
"<PenTool: 0x8b38780;>"
)
The above code works fine. Save in plist. Now I want to get back all the objects from that plist.
Read from plist
NSData *data=[NSData dataWithContentsOfFile:[DOCUMENTPATH stringByAppendingPathComponent:@"1.plist"]];
self.pathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Here I am getting a data. but not a array. I have read about that but there are saying you have to unarhive data. But i don't have idea how to unarhive.
EDIT
I know I have to use below two method but not getting a idea.
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
}
Is there any other way to store custom objects in file.