Swift Language Closures Closures and Type Alias


A closure can be defined with a typealias. This provides a convenient type placeholder if the same closure signature is used in multiple places. For example, common network request callbacks or user interface event handlers make great candidates for being "named" with a type alias.

public typealias ClosureType = (x: Int, y: Int) -> Int

You can then define a function using the typealias:

public func closureFunction(closure: ClosureType) {
    let z = closure(1, 2)
closureFunction() { (x: Int, y: Int) -> Int in return x + y }