我正在尝试使用UserDefaults保留条形图值,以便每次调用应用程序时它都不会显示空白图表。
let defaults = UserDefaults.standard
let dataSet = BarChartDataSet(values: [entry1, entry2, entry3, entry4], label: "Widgets Type")
let data = BarChartData(dataSets: [dataSet])
let encodedData = NSKeyedArchiver.archivedData(withRootObject: data)
defaults.set(encodedData, forKey: "encoded data")
defaults.synchronize()
if let decodedData = defaults.object(forKey: "encoded data") as? Data {
let data = NSKeyedUnarchiver.unarchiveObject(with: decodedData )
barChart.data = data as? ChartData
但是当我运行我的应用程序时,我收到以下错误消息
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Charts.BarChartData encodeWithCoder:]: unrecognized selector sent to instance