Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@doronkatz
Created April 6, 2015 22:06
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 doronkatz/f2ec5901b46f325032ad to your computer and use it in GitHub Desktop.
Save doronkatz/f2ec5901b46f325032ad to your computer and use it in GitHub Desktop.
Nested Functions
private func eatFood(IamHungry: Bool) ->String {
return IamHungry? eatDinner(1) : eatSnack(1)
}
private func eatFood(IamHungry: Bool) -> String{
func eatDinner(quantity: Int) -> String{
return "I am eating dinner"
}
func eatSnack(quantity: Int) -> String{
return "I am eating a snack"
}
return IamHungry ? eatDinner : eatSnack
}
let mealDecider = eatFood(true)
println(mealDecider)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment