From the course: Learning Higher-Order Functions with Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Closure optimizations
From the course: Learning Higher-Order Functions with Swift
Closure optimizations
- Now we're going to talk about something really cool. I really like closure optimizations. They really make the code focused and concise and really communicate, to my opinion, the intent of the code and also makes it hard for other people to change it in such a way that goes against the intention. So one optimization is trailing closures. We've seen this the whole time. I just wasn't pointing it out but now we're going to look at it in detail. Also inferred parameter and return types. Implicit return of single-expression closures. Then we're going to look at shorthand argument names. It all results in efficient, readable focused and clear on intent code. So let's look at some of these closure optimizations. So back in x code we're going to look at some of our early examples. So I'm going to delete all the code except for our lovely names array. And the first thing we're going to do is we're going to call sort. So names.sort. And I'm going to use the one that doesn't have a return…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.