快速将链接对象保存到Realm数据库 [英] Saving a Linked object to Realm Database in swift
本文介绍了快速将链接对象保存到Realm数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择类别后,我试图在类别中创建列表项,但是当我单击保存"按钮时,什么也没有发生,并且值未保存在领域数据库中.下面是我的代码不起作用
I am trying to create a list item in a category after selecting the category but I when ever I click on the save button, nothing happens and the values dont get saved in the realm database. Below is my code which is not working
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)
}
更多代码将根据要求提供.
further codes would be supplied based on request.
推荐答案
您需要在write callback中添加对象
You need to add the object inside write callback
self.database.add(todoList)
这篇关于快速将链接对象保存到Realm数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文