保存数据数组导致崩溃迅速 [英] saving data array causes crash swift
问题描述
我尝试将一个项目添加到arrar中并保存在Userdefault中,但该应用程序崩溃了,我希望有人指出我做错了什么
I tried adding an item to an arrar and saving in Userdefault but the app crashed and I would love anyone to point me to what I am doing wrong
private func putArray(_ value: GMSAutocompletePrediction?, forKey key: String) {
guard let value = value else {
return
}
log("THE MESSAGE \(value)", .fuck)
var newArray = getArray(forKey: key)
log("THE MESSAGE ARRAY \(newArray)", .fuck)
if newArray.contains(value) {
newArray.remove(at: newArray.firstIndex(of: value)!)
} else {
newArray.append(value)
}
storage.setValue(NSKeyedArchiver.archivedData(withRootObject: newArray), forKey: key)
}
崩溃错误
[GMSAutocompletePrediction encodeWithCoder:]:无法识别的选择器已发送到实例0x2818f9ce0 2019-09-26 13:40:07.300856 + 0100 MAX.NG分段调试[4440:1410011] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[GMSAutocompletePrediction encodeWithCoder:]:无法识别的选择器已发送至实例0x2818f9ce0'
[GMSAutocompletePrediction encodeWithCoder:]: unrecognized selector sent to instance 0x2818f9ce0 2019-09-26 13:40:07.300856+0100 MAX.NG Staging Debug[4440:1410011] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSAutocompletePrediction encodeWithCoder:]: unrecognized selector sent to instance 0x2818f9ce0'
推荐答案
GMSAutocompletePrediction
不符合NSCoding
,因此您不能将其保存为用户默认值,您可以从中提取重要的细节并进行自定义保存模型
GMSAutocompletePrediction
doesn't conform to NSCoding
so you can't save it to user defaults , you may extract important details from it and make a custom model to save
这篇关于保存数据数组导致崩溃迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!