April 2017
Intermediate to advanced
316 pages
9h 33m
English
Then we want to store the list of Todo items in memory. To be able to achieve this, we will create a new class called TodoStore. The code is as follows:
import Vapor final class TodoStore { static let sharedInstance = TodoStore() fileprivate var list: [Todo] = Array<Todo>() private init() { } }
For the sake of simplicity, we make this class a singleton that stores a list of Todo items. Also, we make the init method private to avoid non-shared instance initiation.
Next, we add the following methods:
func addOrUpdateItem(item: Todo) { if self.find(id: item.todoId) != nil { _ = update(item: item) } else { self.list.append(item) } } func listItems() -> [Todo] { return self.list }
As the names suggest, these methods will be ...
Read now
Unlock full access