func calculator (n1: Int, n2:Int, operator : (Int, Int) -> Int) -> Int
return operator(n1,n2)
}
let result = calculator(n1:2, n2:3) {$0 * $1}
print(result)
func multiply (no1:Int, no2:Int) -> Int {
return no1 * no2
}
calculator(n1:2, n2:3, operation: multiply)
간소화 예제
calculator(n1:2, n2:3, operation: multiply)
calculator(n1:2, n2:3, operation: {(no1:Int, no2:Int) -> Int in no1 * no2 })
calculator(n1:2, n2:3, operation: {(no1, no2) in no1 * no2 })
let array = [6,2,3,9,4,1]
func addOne(n1:Int) -> Int {
return n1 + 1
}
array.map(addOne)
아래는 모두 같은 표현임