O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Functions as Return Types

Now that you have more experience with functions and closures, recall from Chapter 12 that every function has a function type that defines its parameter and return types. For example, a function that takes a String argument and returns an Int has the function type of (String) -> Int. Function types are frequently used to determine what sort of closure you need to satisfy a given parameter’s type or what sort of function needs to be returned.

Functions can return other functions as their return type. Remember your little town of Knowhere? It is time to make a function to improve your town. You are going to build some roads.

Listing 13.7 Return to Knowhere

import Cocoa let volunteerCounts = [1,3,40,32,2,53,77,13] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required