【发布时间】:2018-03-10 11:42:28
【问题描述】:
import UIKit
struct Task {
var name: String
var completed: Bool
}
class ListModel {
var tasks: [Task] = [] // array to store tasks of todo list
let defaluts = UserDefaults.standard
func addTask( name: String, completed: Bool ) { // store task with status of complete into array
self.tasks.append( Task( name: name, completed: completed ) )
}
var tasksValue: [Task] { // getter and setter of array tasks
get {
return tasks
}
set {
tasks = newValue
}
}
func save() {
defaluts.set(tasks, forKey: "tasks")
}
func load() {
if let value = defaluts.array(forKey: "tasks") as? [Task] {
tasks = value
}
}
}
当我运行我的程序时,它显示由于未捕获的异常“NSInvalidArgumentException”而终止应用程序的错误,原因:“尝试插入非属性列表对象。
有人可以帮我解决吗?
【问题讨论】: