Post

Replies

Boosts

Views

Activity

Reply to CoreData Transformable Types and SecureCoding
Thanks. The relevant piece that I was missing is that it's not just the literal topLevelClasses that need to be registered with the NSSecureUnarchiveFromDataTransformer, but also any classes contained in the transformable if it's a collection. Therefore, if my NSDictionary has a custom class inside it, I need to register a subclass of NSSecureUnarchiveFromDataTransformer to allow that class. @objc class DataTransformer: NSSecureUnarchiveFromDataTransformer { static let name = NSValueTransformerName(rawValue: String(describing: DataTransformer.self)) @objc(registerValueTransformer) public static func register() { let transformer = DataTransformer() print(DataTransformer.allowedTopLevelClasses) ValueTransformer.setValueTransformer(transformer, forName: name) } override class var allowedTopLevelClasses: [AnyClass] { var topLevelClasses = super.allowedTopLevelClasses let myClasses = [MyClass.self, MyOtherClass.self] topLevelClasses.append(contentsOf: myClasses) return topLevelClasses } }
Feb ’24