I am currently using this blog where it uses custom classes used with NSKeyedArchiver. Everything seems correct but I am wondering how to get different instances of "student".
http://keeptheseinmind.blogspot.com/2011/10/nskeyedarchiver-tutorial.html
In this tutorial, new instances of the custom class "students" are created each time when the application is terminated. And I have assumed that there are many of these "students" instances within the NSKeyedArchiver, but I am only able to access to only one of them.
Saving to the disk
- (void)saveDataToDisk {
NSString *path = @"~/Documents/data";
path = [path stringByExpandingTildeInPath];
NSMutableDictionary *rootObject;
rootObject = [NSMutableDictionary dictionary];
[rootObject setValue:student forKey:@"student"];
[NSKeyedArchiver archiveRootObject:rootObject toFile:path];
}
Loading from the disk
- (void)loadDataFromDisk {
NSString *path = @"~/Documents/data";
path = [path stringByExpandingTildeInPath];
NSMutableDictionary *rootObject;
rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
if ([rootObject valueForKey:@"student"]) {
student = [rootObject valueForKey:@"student"];
}
}
EDIT:
I am mistaken, the instances each time are overwriting each other, each time the application is being terminated. Interesting...
However, my goal is still to create many instances of "students" within one or multiple NSKeyedArchiver. Any ideas would be greatly appreciated.