Last active
May 20, 2018 14:17
-
-
Save dineshba/8f3890b0ffe927cfdbd4cc7e82a52c18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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