An example app created for my blog post Swift Closure: demystifying @escaping and @autoclosure attributes.
The app contains an example of how much powerful are @autoclosure
and @escaping
closure attributes. The app let you select dinamically the action to be executed when a table view cell is selected.
Below an article quote:
In this post I will show you two interesting closure features:
@autoclosure
and@escaping
. An@escaping
closure is passed as a parameter to a function, but it is not executed inside it. So, basically the closure is executed after the function returns. The classical example is a closure being stored in a variable outside that function. An@autoclosure
is a closure without parameter that is automatically created to wrap an expression that’s being passed as an argument to a function. This two attributes combined have great potential. Let's see an example where you can avoid multiple if/switch with the use of closure and these two attributes.
Click here to read the post.