Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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