I am converting my app from Objective-C to Swift and I am having a problem unarchiving (in Swift) my persist objects that were previously archived in Objective-C. For example, I have an NSMutableDictionary file that was archived with the following Objective-C code:
NSString *indexFilename = "somefilename";
NSMutableDictionary *index = [NSMutableDictionary dictionary];
// Dictionary gets populated...
// Save it...
[NSKeyedArchiver archiveRootObject:index toFile:indexFilename];
These files are unarchived just fine in the Objective-C version of the app with:
NSMutableDictionary *index = nil;
if ([[NSFileManager defaultManager] fileExistsAtPath:indexFilename]) {
index = [NSKeyedUnarchiver unarchiveObjectWithFile:indexFilename];
}
But in the new Swift version, the following code sets index to nil:
let filename = "somefilename"
var index = NSKeyedUnarchiver.unarchiveObjectWithFile(filename)
Should this just work or is there something else I need to do to unarchive these files successfully in Swift?
Thanks.