I'm having trouble finding the correct way to conform the the NSSecureCoding
protocol in Swift, specifically when decoding objects that is an array of other objects.
I can't create an NSSet
of class types in swift.
In Objective-C I would use
self.books = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSArray class], [Book class], nil] forKey:@"books"];
in Swift I'm having issues creating the NSSet
like this :
self.books = aDecoder.decodeObjectOfClasses(NSSet().setByAddingObject(NSArray.self).setByAddingObject(Book.self), forKey:"books")
Here's the error:
Type 'NSArray.Type' does not conform to protocol 'AnyObject'
For simple objects:
self.myObject = aDecoder.decodeObjectOfClass(MyObject.self, forKey: "myObject")!
Since Swift 3.0:
self.myObject = aDecoder.decodeObject(of:MyObject.self, forKey: "myObject")!
For nested objects:
NSSet(objects: [NSArray.self, Book.self])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With