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 our data. This is especially good for developing classes and frameworks that are designed to retrieve data from external services, such as web services, databases, or files. This section will show how to develop a class that will execute a closure once our data is ready to return.

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 guests names. Let's take a look at the following code: ...

Get Mastering Swift 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.