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

Function Types

Each function you have been working with in this chapter has a specific type. In fact, all functions do. Function types are made up of the function’s parameter and return types. Consider the sortedEvenOddNumbers(_:) function. This function takes an array of integers as an argument and returns a tuple with two arrays of integers. Thus, the function type for sortedEvenOddNumbers(_:) is expressed as ([Int]) -> ([Int], [Int]).

The function’s parameters are listed inside the left parentheses, and the return type comes after the ->. You can read this function type as: A function with one parameter that takes an array of integers and returns a tuple with two arrays containing integers. For comparison, a function with no arguments ...

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