Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Last active August 21, 2016 00:18
Show Gist options
  • Select an option

  • Save carlynorama/0f6d66b02484df4c69857ae10f1571f3 to your computer and use it in GitHub Desktop.

Select an option

Save carlynorama/0f6d66b02484df4c69857ae10f1571f3 to your computer and use it in GitHub Desktop.
The viewcontroller.swift from super basic hello world app
//Updated 2016/08/20
//carlynorama
//no rights reserved. CC0
import UIKit
class ViewController: UIViewController {
@IBOutlet var numberOfCupsTextField: UITextField!
@IBOutlet var mgCaffineResultLabel: UILabel!
@IBAction func confessButton(_ sender: AnyObject) {
guard !(numberOfCupsTextField.text?.isEmpty)! else {
print("no no no no")
return;
}
//not necessary if using numeric only keyboard, but hey, good to
//have on file
guard let cupsValue:Double = Double(numberOfCupsTextField.text!) else {
print("no no no no 2")
return;
}
print("go go go")
let message = "Forgive me Coffea arabica, I have drunk \(numberOfCupsTextField.text!) cups of coffee.";
print(message);
let amountOfCaffinePerCup:Double = 150;
let totalCaffine = cupsValue * amountOfCaffinePerCup;
let unit = "mg";
let substance = "caffine";
mgCaffineResultLabel.text = String(format: "%.0f %@ of %@ today.", totalCaffine, unit, substance);
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment