December 2015
Intermediate to advanced
400 pages
13h 3m
English
This works, but you can clean up your code. Closure syntax follows this general form:
{(parameters) -> return type in
// Code
}
You write a closure expression inside of the braces ({}).
The closure’s parameters are listed inside of the parentheses immediately after the opening brace.
Its return type comes after the parameters and uses the regular syntax.
The keyword in is used to separate the closure’s parameters and return type from the statements inside of its body.
Refactor your code to use a closure expression: create a closure inline instead of defining a separate function outside of the sort(_:) function.
Listing 13.3 Refactoring your sorting code
import Cocoa var volunteerCounts = [1,3,40,32,2,53,77,13] ...
Read now
Unlock full access