I'm trying to replace my method calls to NSKeyedArchiver and NSKeyedUnarchiver that were recently deprecated in the most recent iOS SDK. I'm trying to implement these calls on an object that conforms to the NSCoding protocol, not the NSSecureCoding protocol.
I managed to replace calls to +[NSKeyedArchiver archivedDataWithRootObject:] with calls to +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:], passing false for requiringSecureCoding and verified that my object is successfully encoding.
However, when I attempted to replace calls to +[NSKeyedUnarchiver unarchiveObjectWithData:] with calls to +[NSKeyedUnarchiver unarchivedObjectOfClasses:fromData:error:], there was no error and the call returned nil. What I found especially odd was that I couldn't trigger the object's implemention of the - (void) encodeWithCoder:(NSCoder *) aCoder method from the NSCoding protocol; the log statement I placed there wasn't triggered.
Here's my call to 'unarchivedObjectOfClasses:fromData:error:':
[NSKeyedUnarchiver unarchivedObjectOfClasses:Cookies.class fromData:data error:&error]
and the old call:
Cookies is a class with 2 properties: one is an enum instance (backed by NSInteger) and the other is a Set of NSStrings
My best guess is that this may be caused by what's here in the method description:
For some reason it appears the image isn't loading. It says "Decodes the root object of the given class from the given archive, previously encoded by NSKeyedArchiver. Enables requiresSecureCoding and sets the decodingFailurePolicy to NSDecodingFailurePolicySetErrorAndReturn. Returns nil if the given data is not valid or cannot be decoded, and sets the error out parameter."
If this is the problem, I'm not sure how to work around this behavior. The only other hint I have about what could be going on is what was said in this forum post (https://forums.developer.apple.com/message/322990#322990) below:
This made me think that there may be analagous behavior in the Objective C APIs, so I tried using the call shown below:
[NSKeyedUnarchiver unarchivedObjectOfClasses:[[NSMutableSet alloc] initWithArray:@[Cookies.class, NSSet.class]] fromData:data error:&error]
That did not work either. Does anyone know how I can rewrite this API to unarchive this class or have any insight as to why I might be experiencing this behavior?