Functional swift: All about Closures
According to apple docs: Closures are self-contained blocks of functionality that can be passed around and used in your code. I tried to include all about closures here in this article. It’s a bit lengthy one. But worth reading it. I guarantee !!!
13 min readJul 21, 2017
Some people say that Functions and closures are the same thing with different syntax. Others say that functions are special kind of closure.
Closures are first-class objects, so that they can be nested and passed around
First, let us know what a function is:
Function:
You define a function with the func
keyword. Functions can take many parameters and return none, one or multiple parameters (using tuples, we can return multiple values at a time).
The above function will take two integers as input and returns a tuple with two integer values. If you have no experience with a tuple, please check my other article here.