I am calling the function archiveQueue to store object of type MYJSON at various times through out the program, and now I want to restore everything that I stored uptill now in an array.
Following is the function that I am using to store the objects :
- (void)archiveQueue:(MYJSON *)msg{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:msg];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myqueue.txt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:file contents:data attributes:nil];
NSLog(@"ArchiveQueue: file = %@", file);
}
Following is the function I am using to restore the objects.
- (void)restoreQueue {
NSLog(@"RestoreQueue: Restoring queue from Document Directory.");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [[paths objectAtIndex:0] stringByAppendingPathComponent: @"myqueue.txt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *data = [fileManager contentsAtPath:file];
// How to unarchive that array of objects being stored.
}
I want to know how should I unarchive everything I stored as an array of objects ?