함수를 표현할때 3가지로 나뉜다.
func 키워드를 이용해 이름을 붙여주는 함수들도 모두 클로저이다. 즉, 이름이 있는 함수(Named Closure), 이름이 없는 함수(Unnamed Closure)이다.
이를 클로저라 부르지 않고 흔히 함수라고 부른다.
func myFunction(closure: () -> Void){
print("I'm my func")
closure()
}
{ (인자들) -> 반환타입 in
실행구문
}
let closure = { () -> () in
print("Closure")
}
let closure: (String, String) -> Void = {
print($0)
print($1)
}
closure("Closure" , "2")
// closure
// 2
let closure = { () -> () in
print("Closure")
}
let closure2 = closure
hello(closure: { () -> () in
print("Hello!")
})
func hello() -> () -> () {
return { () -> () in
print("Hello I'm yoojin!")
}
}
let closure = hello()
closure()
// Hello I'm yoojin!