Created
January 14, 2016 18:43
-
-
Save codelynx/497a2f0feb71aa456bdd to your computer and use it in GitHub Desktop.
switch statement example
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
for thing in things { | |
switch thing { | |
case 0 as Int: | |
print("zero as an Int") | |
case 0 as Double: | |
print("zero as a Double") | |
case let someInt as Int: | |
print("an integer value of \(someInt)") | |
case let someDouble as Double where someDouble > 0: | |
print("a positive double value of \(someDouble)") | |
case is Double: | |
print("some other double value that I don't want to print") | |
case let someString as String: | |
print("a string value of \"\(someString)\"") | |
case let (x, y) as (Double, Double): | |
print("an (x, y) point at \(x), \(y)") | |
case let movie as Movie: | |
print("a movie called '\(movie.name)', dir. \(movie.director)") | |
case let stringConverter as String -> String: | |
print(stringConverter("Michael")) | |
default: | |
print("something else") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment