Skip to content

Instantly share code, notes, and snippets.

@grandadmiral-thrawn
Last active December 24, 2016 02:22
Show Gist options
  • Save grandadmiral-thrawn/191fd8de06caf5c9d8f7130c4e1fe930 to your computer and use it in GitHub Desktop.
Save grandadmiral-thrawn/191fd8de06caf5c9d8f7130c4e1fe930 to your computer and use it in GitHub Desktop.
Ray Wenderlich iOS tutorial 3; Swift has type inference
// In the View Controller the function can either declare variables upon instantiation
// or locally in the function
// But what's cooler is that you can set the function for that variable following declaration with a type specificfunction
// Like the variable difference shown here
@IBAction func showAlert() {
// we don't have to do local instance:
//var difference: Int
// instead Swift just knows
difference = currentValue - targetValue
let message = "The value of the slider is: \(currentValue)" +
"\nThe target value is: \(targetValue)" +
"\n and the difference is \(difference)"
let alert = UIAlertController(title: "hello, world", message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "Awesome", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)
startNewRound()
updateLabels()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment