My problem is that I need to archive/unarchive a custom class from AppAuth library and I will need to compare the results of such process at a point to determine if there was change in the object or not (I only have access to the archived data which would be pulled from cache), however unarchived objects never match for some reason.
Example:
private extension OIDAuthState {
func archive() throws -> Data {
let archived = try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: true)
let archived2 = try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: true)
print(archived.elementsEqual(archived2)) // matches
guard let unarchived: OIDAuthState = try NSKeyedUnarchiver.unarchivedObject(ofClass: OIDAuthState.self, from: archived) else {
throw OneIDServiceError.CannotCastData()
}
guard let unarchived2: OIDAuthState = try NSKeyedUnarchiver.unarchivedObject(ofClass: OIDAuthState.self, from: archived) else {
throw OneIDServiceError.CannotCastData()
}
print(unarchived.isEqual(unarchived2)) // does not match!! But it should!
return try NSKeyedArchiver.archivedData(withRootObject: unarchived, requiringSecureCoding: true)
}
}
Is there something I am failing to see here? Shouldn't these objects match? I tried also re-archiving both objects and comparing the produced data with elementsEqual and I can confirm that the data differs.