중첩함수 1
함수의 반환 타입으로 함수를 사용할 수 있음.
import UIKit
func foo() -> String{
return "this is foo()"
}
func boo() -> (Void -> String){
return foo
}
let b = boo()
b()
func boo() -> Void -> String
import UIKit
func plus(a : Int, b : Int) -> Int{
return a + b
}
func minus(a : Int, b : Int) -> Int{
return a - b
}
func times(a : Int, b : Int) -> Int{
return a * b
}
func devide(a : Int, b : Int) -> Int{
guard b != 0 else{
return 0
}
return a / b
}
func calc(operand:String) -> (Int, Int) -> Int{
switch operand {
case "+":
return plus
case "-":
return minus
case "/":
return devide
case "*":
return times
default:
return plus
}
}
let c = calc("+")
c(3,4)
calc("+")(3,4)