Shorthand syntax for closures

In this section, we will look at a couple of ways to shorten the definition of closures.

Note

Using the shorthand syntax for closures is really a matter of personal preference. There are a lot of developers that like to make their code as small and compact as possible and they take great pride in doing so. However, at times, this can make code hard to read and understand by other developers.

The first shorthand syntax for closures that we are going to look at is one of the most popular and is the syntax we saw when we were using algorithms with arrays in Chapter 3, Using Collections and Cocoa Data Types. This format is mainly used when we want to send a really small (usually one line) closure to a function, like we did ...

Get Mastering Swift 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.