Closures include:
global functions, nested functions, and closure expressions
Nested functions
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID178
closure expression- an unnamed, self contained block of code
closure expression are used to specify an action to be executed some time in the future.
var bids = [48, 75, 63, 52, 68] var orderedBids = bids.sort( {(bid1: Int, bid2: Int) -> Bool in return bid2 > bid1 }) print(orderedBids)
Closures typically take the form:
{(parameters) -> return type in
statements to execute
}
var birthYears = [2004, 2011, 2007, 2005, 2002] var reverseChronologicalYears = birthYears.sort({ (year1: Int, year2: Int) -> Bool interface EarthquakeActivity extends Parent { return year1 > year2 } })