Declare a function with default values


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


// 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

// Let's call it again
// with some parameter


Find answers here

Hi there! Ask Us a Question We are ready to help