In a class, I call the following (edited to simplify, but it matches the real case).
If I do this:
func getData() -> someClass? {
_ = someURL.startAccessingSecurityScopedResource()
if let data = NSData(contentsOf: someURL as URL) {
do {
let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data as Data)
print((unarchiver.decodeObject(of: [NSArray.self, someClass.self /* and few others*/], forKey: oneKey) as? someClass)?.aProperty)
if let result = unarchiver.decodeObject(of: [NSArray.self, someClass.self /* same other types*/], forKey: oneKey) as? someClass {
unarchiver.finishDecoding()
print("unarchived success")
return result
} else {
unarchiver.finishDecoding()
print("unarchiving failed")
return someClass()
}
}
catch {
return nil
}
}
I get a failure on log : unarchiving failed
But if I comment out the print(unarchiver.decodeObject) - line 8, it works and I get unarchived success
// print((unarchiver.decodeObject(of: [NSArray.self, someClass.self /* and few others*/], forKey: oneKey) as? someClass)?.aProperty)
However, when I do exactly the same for another class (I've compared line by line to be sure), it works even with the print statement.
What could be happening here ?