Functions

Definition

func functionName (parameters) -> ReturnType {
  //body of the function 
}

External and local names for arguments

func sayHello(to person: String, and anotherPerson: String) {
  print("Hello \(person) and \(anotherPerson)")
}
 
sayHello(to: "Miles", and: "Riley")

Omit the external name

“func sayHello(_ person: String, _ anotherPerson: String) {
  print("Hello \(person) and \(anotherPerson)")
}
 
sayHello("Luke", "Dave")

set defaults  

func display(teamName: String, score: Int = 0) {
  print("\(teamName): \(score)")
}
 
display(teamName: "Wombats", score: 100) //"Wombats: 100"

display(teamName: "Wombats") //"Wombats: 0"

Return types

func multiply(firstNumber: Int, secondNumber: Int) -> Int {
  let result = firstNumber * secondNumber
  return result
}

Excerpts From: Apple Education. “App Development with Swift.” Apple Inc. - Education, 2017. iBooks. https://itunes.apple.com/au/book/app-development-with-swift/id1219117996?mt=11

Swift Structures