Multiple Trailing Closures

Updated:

🔷 Multiple Trailing Closures

Multiple trailing closure - https://github.com/apple/swift-evolution/blob/master/proposals/0279-multiple-trailing-closures.md

// swift 5.3
// 매개 변수로 클로저를 다수로 가지는 메소드
func someFunctionWithClosure(completion: () -> Void,
														 secondCompletion: (String) -> Void,
														 thirdCompletion: (Int) -> Void) {
	print("someFunctionWithColsure() called")

	completion()
	secondCompletion("두번째 클로져")
	thirdCompletion(3)
}

// 멀티 트레일링 클로저 사용이 가능합니다
someFunctionWithClosure {

} secondCompletion: {
	print("\($0)")
} thirdCompletion: {
	print("\($0)")
}

// someFunctionWithColsure() called
// 두번째 클로져
// 3



Reference

Swift Tip of the day - 스위프트 기초 문법 - https://spangle-wedelia-2dc.notion.site/Swift-Tip-of-the-day-c428bfd990674bcfa2a4973e5d08c4eb

꼼꼼한 재은 씨의 스위프트 문법편 - https://book.jacobko.info/#/book/1186710233

Categories:

Updated:

Leave a comment