快速将链接对象保存到Realm数据库

时间:2018-09-08 11:05:09

标签: ios swift realm

选择类别后,我试图在类别中创建列表项,但是当我单击保存按钮时,什么也没有发生,并且值未保存在领域数据库中。下面是我的代码不起作用

func createTodoList(name: String, description: String, createdDate: Date, remiderDate: Date, isCompleted: Bool) -> Void {

        let item = TodoListVC()

        if let currentCategory = item.selectedCategory {

            do {
                try self.database.write {
                    let todoList = TodoListModel()
                    todoList.name = name
                    todoList.desc = description
                    todoList.createdDate = createdDate
                    todoList.isCompleted = false

                    currentCategory.items.append(todoList)
                }
            } catch {
                print("error items")
            }
        }
}

创建VC

@IBAction func saveBtn(sender: AnyObject) {

        TodoListFunctions.instance.createTodoList(name: name, description: description, createdDate: Date(), isCompleted: false)

        dismiss(animated: true, completion: nil)
    }

更多代码将根据要求提供。

1 个答案:

答案 0 :(得分:0)

您需要在写回调中添加对象

self.database.add(todoList)
相关问题