Skip to content

Instantly share code, notes, and snippets.

@natanrolnik
Created February 7, 2019 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natanrolnik/cad60f15f12db2bd6394e50f26d11d0b to your computer and use it in GitHub Desktop.
Save natanrolnik/cad60f15f12db2bd6394e50f26d11d0b to your computer and use it in GitHub Desktop.
if and switch as expressions
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