Last active
August 29, 2015 14:02
-
-
Save stefanlindbohm/9e19e92e01c3274247e3 to your computer and use it in GitHub Desktop.
Naming arguments in Swift
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
// 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