最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Unarchived objects with NSKeyedUnarchiver not matching - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论