Using important Swift features
We've now covered the basics of Swift, in addition to the building blocks we need to create robust classes and organized data with structs and enums. With these tools, you'd be able to accomplish some great things, but there are a few other important features of Swift that can save you a lot of time, and help you squeeze out even more performance from your code. In this last section, we are going to introduce closures, protocols, class extensions, and Swift's error handling features.
Closures
We've already talked about functions, where we can take a chunk of code and turn it into a reusable command. However, in Swift there is another way to achieve that kind of functionality (no pun intended): closures. Using closures is a great way to pass a chunk of code (sometimes called a block) into a function as an argument, and they're commonly used as completion or error handers. Let's take a look at an example:
// defining a simple closure...