O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

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

Standalone closures and good style guidelines

Closures give us the ability to truly separate the data portions of our code from the user interface and business logic portions. This gives us the ability to create reusable classes that focus solely on retrieving the data. This is especially good for developing types and frameworks that are designed to retrieve data from external services, such as web services, databases, or files. In this section, I will show you how to develop a type that will execute a closure once our data is returned.

Let's begin by creating a class that will contain the data portion of our code. In this example, the class will be named Guests, and it will contain an array of guest's names. Let's look at the following code: ...

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