Created
February 7, 2019 11:09
-
-
Save natanrolnik/cad60f15f12db2bd6394e50f26d11d0b to your computer and use it in GitHub Desktop.
if and switch as expressions
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
import Foundation | |
let randomInt = Int.random(in: 0...3) | |
let spelledOut: String = { | |
switch randomInt { | |
case 0: | |
return "Zero" | |
case 1: | |
return "One" | |
case 2: | |
return "Two" | |
case 3: | |
return "Three" | |
default: | |
return "Out of range" | |
} | |
}() | |
print(spelledOut) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment