first you need to customize your models so that your todo can be saved in the area.
All you have to do is have it in one of your files (preferably the todo.swift file)
class Todo: RLMObject { dynamic var name = "" }
Then you can create your first two icons by following these steps:
var firstTodo = Todo() firstTodo.name = "My first thing todo!" var secondTodo = Todo() secondTodo.name = "My second thing todo!"
Then you can save it in the kingdom
let realm = RLMRealm.defaultRealm() realm.beginWriteTransaction() realm.addObject(firstTodo) realm.addObject(secondTodo) realm.commitWriteTransaction()
Now you can capture all your todos that return an array of them
let arrayOfTodos = Todo.allObjects()
If I were to create a method to save new todos, I would do something like this
func createNewTodo(todo: String){ let todo = Todo() todo.name = todo let realm = RLMRealm.defaultRealm() realm.beginWriteTransaction() realm.addObject(todo) realm.commitWriteTransaction() }
source share