Declare a function with return type

 Problem

I want to declare a new function which takes some arguments and returns a result.



 Recipe


// Declare our new function
func multiply(a:Int, with:Int)->Int {
    return a*with
}

// Call it
let product = multiply(2, with:5)

print(product)


				

Heard the news?

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

 

 Playground