SO apparently, what I didn't know was that you have to save your root object, in this case an array, to an NSMutableDictionnary first.
NSMutableDictionary *rootObject;
rootObject = [NSMutableDictionary dictionary];
[rootObject setValue: self.devices forKey: @"devices"];
And then save the rootObject with the NSKeyedArchiver. Weird, hadn't seen this in any of the tutorials.
So you end up with the following functions for loading and saving the data to the NSKeyedArchiver.
- (void) loadArrayFromArchiver {
NSMutableDictionary *rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile: [self getDataPath]];
if ([rootObject valueForKey: @"devices"]) {
self.devices = [rootObject valueForKey: @"devices"];
}
NSLog(@"Unarchiving");
}
- (void) saveArrayToArchiver {
NSLog(@"Archiving");
NSMutableDictionary *rootObject = [NSMutableDictionary dictionary];
[rootObject setValue: self.devices forKey: @"devices"];
[NSKeyedArchiver archiveRootObject: rootObject toFile: [self getDataPath]];
}
- (NSString *) getDataPath {
self.path = @"~/data";
path = [path stringByExpandingTildeInPath];
NSLog(@"Creating path");
}