Background
We have multiple classes that conform to NSSecureCoding
protocol.
@interface ClassA : NSObject <NSSecureCoding>
// ...
@end
@interface ClassB : NSObject <NSSecureCoding>
// ...
@end
We notice that NSArray
also conforms to NSSecureCoding
. Therefore, we try the following.
For encoding:
NSArray* array = ...
[archiver encodeObject:array forKey:@"AirdropDataKey"];
For decoding
NSArray* array = [unarchiver decodeObjectOfClass:[NSArray class]
forKey:@"AirdropDataKey"];
And I get this following error message.
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'value for key 'NS.objects' was of unexpected class 'ClassA'. Allowed classes are '{(
NSArray
)}'.'
Anybody could explain why and whether it is possible to resolve this issue?
NSSecureCoding
but have toNSCoding
? – Glyceric