I am trying to replace the deprecated unarchiveObjectWithData API with unarchivedObjectOfClass.
My class looks something like this
Class B:<<NSSecureCoding>
{
- (BOOL)supportsSecureCoding
{ return YES; }
}
Class C <<NSSecureCoding>
{ property of class B;
- (BOOL)supportsSecureCoding
{ return YES; } }
Class A<<NSSecureCoding> {
property of class B property of class c
- (BOOL)supportsSecureCoding
{ return YES; }
}
Tried solutions:
-
Archive code
NSData *archiveData = [NSKeyedArchiver archivedDataWithRootObject:(array of objects of type A) requiringSecureCoding:YES error:&error];
// Encrypting archiveData and writing to file
Unarchive code
// fetching data from file // decrypting it
NSSet *classesSet = [NSSet setWithObjects: [NSMutableArray classForCoder], [A classForCoder], [NSString classForCoder], [NSNumber classForCoder], [B classForCoder], [C classForCoder] , nil]; NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:decryptedData error:&error]; [unArchiver setRequiresSecureCoding:YES]; array of objects of Type A = [unArchiver decodeObjectOfClasses:classesSet forKey:NSKeyedArchiveRootObjectKey];
Issue:
Unable to unarchive all the properties. Properties have nil values including properties of type NSString, BOOL, custom class
Use +unarchivedObjectOfClass:fromData:error
Unarchive code:
NSSet *classesSet = [NSSet setWithObjects: [NSMutableArray classForCoder], [A classForCoder], [NSString classForCoder], [NSNumber classForCoder], [B classForCoder], [C classForCoder] , nil];
array of objects of Type A = [NSKeyedUnarchiver unarchivedObjectOfClasses:classesSet fromData:storeData error:&error]
Issue:
"UserInfo={NSDebugDescription=value for key 'root' was of unexpected class 'Class B'. Allowed classes are '{NSMutable Array}"
Can someone please assist with this issue. I have tried all the available solutions online. I couldn't find a documentation from Apple on how to consume the new API in a correct way.