I have an Objective-C protocol that requires conformance to NSSecureCoding
:
@protocol MyProtocol <NSObject, NSSecureCoding>
…
@end
I have a parent object that stores a reference to an object conforming to MyProtocol
, and I would like the parent object to also conform to NSSecureCoding
. When I try this:
required init?(coder aDecoder: NSCoder) {
if let childObject = aDecoder.decodeObject(of: MyProtocol.self, forKey: "childObject") {
self. childObject = childObject
} else {
return nil
}
}
I get the error: 'decodeObject(of:forKey:)' is unavailable in Swift: use generic 'decodeObjectOfClass(_:forKey:)'
.
Is there any way to use NSSecureCoding if you don't know the specific class of the object you encoded?