I'm getting the following exception when trying to unarchive when using Swift:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (NSKnownKeysDictionary1) for key (NS.objects); the class may be defined in source code or a library that is not linked'
The context: I'm creating a "Share Links" extension. In my main app (written in Objective C) I write out an array of dictionaries with the information about the links using MMWormhole.
NSFetchRequest* bookmarkFetch = [NSFetchRequest fetchRequestWithEntityName:@"XX"]; bookmarkFetch.propertiesToFetch = @[ @"name", @"text", @"date", @"url" ]; bookmarkFetch.resultType = NSDictionaryResultType; NSArray* bookmarks = [moc executeFetchRequest:bookmarkFetch error:NULL]; [wormhole passMessageObject:bookmarks identifier:@"XXX"];
The values in the array are NSStrings and an NSDate.
In the bowels of MMWormhole you get:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:messageObject];
messageObject is just the bookmarks array without any intermediate processing.
In the extension I have:
let wormhole = MMWormhole(applicationGroupIdentifier: "group.XX", optionalDirectory:nil) let bookmarks = wormhole.messageWithIdentifier("XXX") as? Array<Dictionary<String,AnyObject>>
messageWithIdentifier: ends up calling this ultimately:
id messageObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
The array is written out to the app group folder correctly -- I can read it using another extension, one written in Objective C.
This exception appears when I run in the Simulator. The code appears to work correctly when run on a 32-bit device (iPhone 5 and iPad 3). I don't have a 64-bit device to test on currently.
I imagine I'm missing an import
or a framework, but which one(s)?