I get a code-time yellow warning message in Xcode that says:
'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead
... when I use the following code:
let oldUbiquityIdentityToken = NSKeyedUnarchiver
.unarchiveObject(with: oldDataUbiquityIdentityToken!)
When I change to unarchivedObject(ofClass:from:) I get 2 code-time red error messages before I even fill in the arguments:
'NSCoding' cannot be used as a type conforming to protocol 'NSCoding' because 'NSCoding' has static requirements
Static method 'unarchivedObject(ofClass:from:)' requires that 'NSCoding' inherit from 'NSObject'
Here is the code afterwards before I fill in the parameters:
let oldUbiquityIdentityToken = NSKeyedUnarchiver.unarchivedObject(ofClass: NSCoding.Protocol, from: Data)
Why am I getting these error messages?
Thanks for showing the info about how `oldDataUbiquityIdentityToken` is made.
As you have found in the doc, the return type of `ubiquityIdentityToken` is sort of an opaque type.
You cannot use ` unarchivedObject(ofClasses:from:)` or `unarchivedObject(ofClass:from:)` for such an object,
you need to know the definite class of the object, not protocols.
In this case, you can use another method:
do {
let oldUbiquityIdentityToken = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(oldDataUbiquityIdentityToken!)
//...
} catch {
print(error)
}