Closure : 코드 안에서 전달되어 사용할 수 있는 로직을 가진 중괄호 {} 로 구분된 코드의 블록
function은 closure의 한 형태로, 이름이 있는 Closure라고 생각하면됨
var mulpiClosure: (Int, Int) -> Int = {a, b in
return a * b
}
// Closure : method, but there isn't name
import UIKit
var muliplyClosure : (Int, Int) -> Int = {$0 * $1}
var mulpiClosure: (Int, Int) -> Int = {a, b in
return a * b
}
func operateTwoNum(a: Int, b: Int, opertion: (Int, Int) -> Int) -> Int {
let result = opertion(a, b)
return result
}
operateTwoNum(a: 4, b: 2, opertion: muliplyClosure)
operateTwoNum(a: 4, b: 2) {a, b in
return a/b
}