Trailing Closure : Swift
How to Create function without name !!
Introduction:
Previous part we learn and examine how to create closure in many way and how to pass and return from a function.In this part we will discussed about trilling closure
Trailing closure :
Trailing closure is just pass closure on function after its call’s parentheses as a final parameter .Lets give example :
Here i create an function which can take a closure .Now lets implement it using normal closure directly on function :
Now use trilling closure like this
So here we use closure parameter after its call’s parentheses.When argument become too long .And in trilling closure we don’t need to write argument name .If function have one one argument and its closure than we don’t need to write parentheses.Than its become like this
Its beauty of closure !!