Skip to content

Instantly share code, notes, and snippets.

@rtking1993
Created March 30, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtking1993/9d118e0a3539680c67eb77eb30184cd7 to your computer and use it in GitHub Desktop.
Save rtking1993/9d118e0a3539680c67eb77eb30184cd7 to your computer and use it in GitHub Desktop.
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