Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The body methods of the MainViewController for our dynamic list
// MARK: View Methods
override func viewDidLoad() {
super.viewDidLoad()
loadItems()
}
// MARK: Action Methods
@IBAction func add(_ sender: Any?) {
guard let itemText = addTextField.text else {
return
}
textFieldFinished()
let item: Item = Item(item: itemText)
ItemsRemote.postItem(item: item)
}
// MARK: Helper Methods
private func loadItems() {
ItemsRemote.getAllItems { items in
self.items = items
}
}
private func textFieldFinished() {
addTextField.text = nil
addTextField.resignFirstResponder()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment