我的代码有一个小问题。当我从 CoreData 加载数据时,我在控制台中收到警告,但我不知道为什么。我不是专业程序员,谷歌也无法真正帮助我,所以现在我在这里。
我像这样加载数据:
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var data: [DataToLoad] = []
override func viewDidLoad(){
do{
data = try context.fetch(DataToLoad.fetchRequest())
}catch{
print("error")
}}
但是当我像控制台那样加载它时......
“2020-09-05 20:32:04.884728+0200 Test-Application[3850:348569] [一般]‘NSKeyedUnarchiveFromData’不应用于取消存档,并将在未来版本中删除”
...启动应用程序后。
所以我的意思是一切都工作正常,但是这个按摩出现的错误在哪里。 我希望你能帮助我。
抱歉我的英语不好,我希望你能理解一切。
祝你有美好的一天,谢谢大家。
最佳答案
该应用仍在运行,因为它是一个警告,而不是错误,但最好不要忽略警告。
在您的情况下,出现警告是因为 NSKeyedUnarchiveFromData
已被弃用。这意味着它已经过时,将来将会被替换,然后应用程序可能会停止工作。
凯拉·迪亚涅 (Kaira Diagne) 解释道:
With iOS 12 Apple has started adopting
NSSecureCoding
across the entire platform. For Core Data this means that the defaultValueTransformer
, which usesNSCoding
to transform a custom data type into a format that can be stored in the persistent store, at some point will change as well.
在您的情况下,核心数据中的 NSSecureUnarchiveFromData
而不是 NSKeyedUnarchiveFromData
。
This means that the first thing we need to do is make sure that the data type of every transformable property in our data model conforms to secure coding.
(链接:NSSecureCoding and transformable properties in Core Data,2020)
为了让您的应用程序在将来也能正常工作,您必须更深入地研究代码,看看在哪里使用了已弃用的方法和类并替换它们。
关于swift - 从 Coredata 加载数据时,我在控制台中收到警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63757527/