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

13 Closures

Closures are discrete bundles of functionality that can be used in your application to accomplish specific tasks. Functions, which you learned about in the last chapter, are a special case of closures. You can think of a function as a named closure.

In Chapter 12, you worked primarily with global and nested functions. Closures differ from functions in that they have a more compact and lightweight syntax. They allow you to write a function-like construct without having to give it a name and a full function declaration. This makes closures easy to pass around in function arguments and returns.

Let’s get started. Create a new playground called Closures.

Closure Syntax

Imagine that you are a community organizer ...

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