Declare a function with default values

 Problem

I want to declare a function which takes one or more parameters, with default values.



 Recipe


// Declare a function with one parameter
// which has a default value set
func sayHello(whom : String = "World") {
    print ("Hello \(whom)!")
}

// Call it without any parameter
// and the 'default' one will be used
sayHello()

// Let's call it again
// with some parameter
sayHello("John")
				


 Playground