Passing function within function parameter swift

By | July 29, 2016

Passing function within function parameter swift

This is one of the powerful feature of swift. That’s called “function type” that means function itself is a type and you can pass this function to another function. For example (Int,Int) -> Int that means you can pass any such function which takes two integer parameters and returns an integer.

Below is a great example done by me, would be easy to understand the concept.

So, in above program we have to similar type of functions. addTwoNum and mulTwoNum. Another function is testFunc – that takes two integers and a function as a parameter. Wonderful is that we passed first addTwoNum as parameter and then mulTwoNum and we got both results accordingly.

Leave a Reply

Your email address will not be published. Required fields are marked *