I need any kind of help I can get on this question and am open to any solutions or workarounds.
When I archive FileManager.ubiquityIdentityToken with NSKeyedArchiver.archivedData(withRootObject:requiringSecureCoding:), what should I set the second parameter to in order to be able to unarchive later, and how do I unarchive the Data object using unarchivedObject(ofClass:from:) or any other method of NSKeyedUnarchiver?
My code currently uses the deprecated method of archivedData(withRootObject:)
, which gives me a code time warning saying:
'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead
I'm getting code time error messages in red for the argument to archivedData(withRootObject:requiringSecureCoding:) which is declared as type Any. I tried different arguments. The one I this should work is (NSCoding & NSCopying & NSObject).Type
, which generates two error messages:
Static method 'unarchivedObject(ofClass:from:)' requires that '(NSObject & NSCoding & NSCopying).Type' inherit from 'NSObject' Type '(NSObject & NSCoding & NSCopying).Type' cannot conform to 'NSCoding'
Setting the argument to (NSCoding & NSCopying & NSObject)
generates the error message:
'NSObject & NSCoding & NSCopying' cannot be used as a type conforming to protocol 'NSCoding' because 'NSCoding' has static requirements
I haven't been able to discover what that means that 'NSCoding' has static
I get the idea to use (NSCoding & NSCopying & NSObject)
because when run code:
print("type of FileManager.default.ubiquityIdentityToken: \(type(of: FileManager.default.ubiquityIdentityToken))")
the debug window shows
type of FileManager.default.ubiquityIdentityToken: Optional<NSCoding & NSCopying & NSObject>
but when I run the following code
print("type of FileManager.default.ubiquityIdentityToken: \(type(of: FileManager.default.ubiquityIdentityToken!))")
I get the following in the debug window
type of FileManager.default.ubiquityIdentityToken: _NSInlineData
I read on stackoverflow that "_NSInlineData" is not made available to us by Apple.
I'm open to doing this any other way, not necessarily with NSKeyedArchiver or NSKeyedUnarchiver, including using unsafe pointers if necessary.
In one of Apple's documentation or sample Xcode projects, I found code to check the login status of a user on iOS when an app logs on by checking FileManager.ubiquityIdentityToken and to check the current status with the previous status by checking the ubiquityIdentityToken that was saved in UserDefaults. Is there a better way of doing this?