Declare a Function With Default Parameter Value

In this short Swift code example we will learn how to declare a function with one parameter with a Default value.

  • Declare a function,
  • Declare one function with default parameter value.
// Declare a function with one parameter with a Default value
func printName(name : String = "Guest") {
    print ("Hi \(name)!")
}

// Call function.
// Function will use the parameter value sent
printName("Sergey")

// Call function. 
// This time a parameter Default value will be used
printName()

[raw_html_snippet id=”cookbookpagecoursesheader”]

Unit Testing Swift Mobile App

Apply Test-Driven Development(TDD) process to iOS mobile app development in Swift Preview this video course.