gpt4 book ai didi

ios - NSKeyedUnarchiver.unarchiveObject 不工作

转载 作者:行者123 更新时间:2023-11-28 12:28:59 25 4
gpt4 key购买 nike

<分区>

NSKeyedArchiver.archiveRootObject 被调用,但 getter 返回变量 'a' 为 nil。这让我很烦。

有人看到这里的问题是什么吗?

let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("Information.ab")

var info: Information? {
get {
let a = NSKeyedUnarchiver.unarchiveObject(withFile: url.absoluteString) as? Information
return a
}
set {
if info != newValue && newValue != nil {
NSKeyedArchiver.archiveRootObject(newValue as Any, toFile: url.absoluteString)
}
}
}

class Information: RecordModel {

let rules: CKAsset
let aboutUs: String
let terms: String
let privacyPolicy: String

override init(record: CKRecord) {
rules = record["rules"] as! CKAsset
aboutUs = record["aboutUs"] as! String
terms = record["terms"] as! String
privacyPolicy = record["privacyPolicy"] as! String
super.init(record: record)
}

}

class RecordModel: NSObject, NSCoding {

let record: CKRecord

init(record: CKRecord) {
self.record = record
}

required convenience init?(coder aDecoder: NSCoder) {
let record = aDecoder.decodeObject(forKey: "keyRecord") as! CKRecord
self.init(record: record)
}

func encode(with aCoder: NSCoder) {
aCoder.encode(record, forKey: "keyRecord")
}

override func isEqual(_ object: Any?) -> Bool {
if let rhs = object as? Information {
return record.recordID == rhs.record.recordID
}
return false
}

override var hash: Int {
return record.recordID.hashValue
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com