var closureName: (ParameterTypes) -> ReturnType = { ... }
var closureName: ((ParameterTypes) -> ReturnType)?
typealias ClosureType = (ParameterTypes) -> ReturnType
let closureName: ClosureType = { ... }
funcName(parameter: (ParameterTypes) -> ReturnType)
Note: if the passed-in closure is going to outlive the scope of the method, e.g. if you are saving it to a property, it needs to be annotated with @escaping.
funcName({ (ParameterTypes) -> ReturnType in statements })
array.sorted(by: { (item1: Int, item2: Int) -> Bool in return item1 < item2 })
array.sorted(by: { (item1, item2) -> Bool in return item1 < item2 })
array.sorted(by: { (item1, item2) in return item1 < item2 })
array.sorted { (item1, item2) in return item1 < item2 }
array.sorted { return $0 < $1 }
array.sorted { $0 < $1 }
array.sorted(by: <)
array.sorted(by: { [unowned self] (item1: Int, item2: Int) -> Bool in return item1 < item2 })
array.sorted(by: { [unowned self] in return $0 < $1 })