Hello,
Thank you for your detailed response to my previous question.
I understand that including all classes used within the app in the ofClasses parameter is not the correct pattern.
Situation Update:
Following your advice, I tested by including only the root object's class in ofClasses. Class X contains nested objects Y and Z.
// Including only root object and some nested objects
NSKeyedUnarchiver.unarchivedObject(ofClasses: [X.self, Y.self], from: data)
Problem Encountered:
However, I encountered the following error:
Error Domain=NSCocoaErrorDomain Code=4864 "value for key 'anotherNestedObject' was of unexpected class 'Z'.
Allowed classes are: { 'X', 'Y' }"
The error was only resolved when I included class Z in ofClasses as well.
Current Implementation Verification:
Class X properly implements NSSecureCoding
In the init(coder:) method, it individually decodes nested objects using coder.decodeObject(ofClass: Y.self, forKey: "nestedObject") and coder.decodeObject(ofClass: Z.self, forKey:
"anotherNestedObject")
Classes Y and Z also properly implement NSSecureCoding
Question:
Even though each class properly implements NSSecureCoding and individually decodes nested objects, why do I still need to include all nested classes in the root-level ofClasses parameter? Is this
the intended behavior of the NSKeyedUnarchiver.unarchivedObject(ofClasses:from:) method, or is there a different implementation approach needed to apply the pattern where "you only have to list the
class of the root object"?
Thank you.