Use closure as a parameter


I want to declare a function that takes a closure as a parameter and then call it.


// Declare a function
// that takes a closure (with 2 integer parameters)
// as an argument

func doSth(action:(Int,Int)->()) {
    // Run the passed 'action'
    // with the parameters: 2, 5

// Call it
doSth({(x:Int, y:Int)->() in
    print("x * y = \( x * y )")

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)