Skip to content

Instantly share code, notes, and snippets.

@stefanlindbohm
Last active August 29, 2015 14:02
Show Gist options
  • Save stefanlindbohm/9e19e92e01c3274247e3 to your computer and use it in GitHub Desktop.
Save stefanlindbohm/9e19e92e01c3274247e3 to your computer and use it in GitHub Desktop.
Naming arguments in Swift
// Defaults: inconsistent calls
class Default {
init(first: Int, second: Int) { }
func method(first: Int, second: Int) { }
}
func defaultFunction(first: Int, second: Int) { }
let defaultObject = Default(first: 1, second: 1)
defaultObject.method(1, second: 1)
defaultFunction(1, 1)
// No named arguments: random underlines in declarations
class NoNamed {
init(_ first: Int, _ second: Int) { }
func method(first: Int, _ second: Int) { }
}
func noNamedFunction(first: Int, second: Int) { }
let noNamedObject = NoNamed(1, 1)
noNamedObject.method(1, 1)
noNamedFunction(1, 1)
// All named arguments: random hashes in declarations
class AllNamed {
init(first: Int, second: Int) { }
func method(#first: Int, second: Int) { }
}
func allNamedFunction(#first: Int, #second: Int) { }
let allNamedObject = AllNamed(first: 1, second: 1)
allNamedObject.method(first: 1, second: 1)
allNamedFunction(first: 1, second: 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment