Skip to content

Instantly share code, notes, and snippets.

@dineshba
Last active May 20, 2018 14:17
Show Gist options
  • Save dineshba/8f3890b0ffe927cfdbd4cc7e82a52c18 to your computer and use it in GitHub Desktop.
Save dineshba/8f3890b0ffe927cfdbd4cc7e82a52c18 to your computer and use it in GitHub Desktop.
// mandatory argument names for caller
func add(augend: Int, addend: Int) -> Int {
return augend + addend
}
let sum = add(augend: 5, addend: 2)
// no argument names for caller (underscore for no name)
func add(_ augend: Int, _ addend: Int) -> Int {
return augend + addend
}
let sum = add(5, 2)
// Two names for an argument. 1. For caller 2. For function definition
// Note: and, addend for 2nd parameter in below function
// `and` will be used by caller, `addend` will used by function definition
func add(_ augend: Int, and addend: Int) -> Int {
return augend + addend
}
let sum = add(5, and: 2) // for readability, we can have one name at calling place
// and one name at function definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment