Skip to content

Instantly share code, notes, and snippets.

@ambientlight
Last active February 2, 2020 14:32
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 ambientlight/443248e0b74765cc7d531ac9c26864b2 to your computer and use it in GitHub Desktop.
Save ambientlight/443248e0b74765cc7d531ac9c26864b2 to your computer and use it in GitHub Desktop.
Crude counter view controller
var appState = 0
let reducer: (Int, Int) -> Int = { (sum, increment) in sum + increment };
class CounterViewController: UIViewController {
@IBOutlet var inputField: UITextField!
@IBOutlet var addButton: UIButton!
@IBOutlet var sumLabel: UILabel!
@IBAction func addButtonPressed(_ sender: UIButton) {
appState = reducer(appState, Int(self.inputField.text!)!)
self.sumLabel.text = "\(appState)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment