I am having trouble with adopting NSSecureCoding. I encode an array containing objects of my custom class, which adopts NSSecureCoding
properly. When I decode i
You've probably already solved this, but I just hit this and found a solution, and thought I'd leave it here for anyone else that finds this.
My solution was to use decodeObjectOfClasses:forKey:
In swift:
if let data = defaults.objectForKey(FinderSyncKey) as? NSData
let unArchiver = NSKeyedUnarchiver(forReadingWithData: data)
unArchiver.setRequiresSecureCoding(true)
//This line is most likely not needed, I was decoding the same object across modules
unArchiver.setClass(CustomClass.classForCoder(), forClassName: "parentModule.CustomClass")
let allowedClasses = NSSet(objects: NSArray.classForCoder(),CustomClass.classForCoder())
if let unarchived = unArchiver.decodeObjectOfClasses(allowedClasses, forKey:NSKeyedArchiveRootObjectKey) as? [CustomClass]{
return unarchived
}
}
in objective-C it would be something like [unArchiver decodeObjectOfClasses:allowedClasses forKey:NSKeyedArchiveRootObjectKey]
The change in decode object to decode objects solved the above exception for me.