来自苹果的Swift编程语言(Swift 5.2beta)
func someFunctionThatTakesAClosure(closure: () -> Void) {
// function body goes here
print("Declaring Function")
}
// Here's how you call this function without using a trailing closure:
someFunctionThatTakesAClosure(closure: {
// closure's body goes here
print("Without Trailing Closure Syntax")
})
// Here's how you call this function with a trailing closure instead:
someFunctionThatTakesAClosure() {
// trailing closure's body goes here
print("Trailing Closure Syntax")
}
在这些例子中,当
someFunctionThatTakesAClosure