Last active
December 24, 2016 02:22
-
-
Save grandadmiral-thrawn/191fd8de06caf5c9d8f7130c4e1fe930 to your computer and use it in GitHub Desktop.
Ray Wenderlich iOS tutorial 3; Swift has type inference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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