Using @autoclosure when designing Swift APIs

The @autoclosure attribute enables us to define function arguments which can be expressed as a simple expression at the call site, but which are then automatically wrapped in a closure. This has the benefit of delaying execution, as with an explicit closure, while also reducing the verbosity of our code. In this post John Sundell provides 3 quick examples of using @autoclosure when designing our APIs. While reading this it's also worth keeping in mind a note from Apple's official Swift programming guide which points out that overusing autoclosures can make our code hard to understand. Use wisely.