Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created April 2, 2015 15:33
Show Gist options
  • Save wjlafrance/296c9321eb8dce253303 to your computer and use it in GitHub Desktop.
Save wjlafrance/296c9321eb8dce253303 to your computer and use it in GitHub Desktop.
Init argument naming conventions
// Which convention for init args do you prefer?
// Naming the arguments the same as the fields requires explicitly naming self
class MyFirstClass {
var i: Int
var s: String
init(i: Int, s: String) {
self.i = i
self.s = s
}
}
// Using different local names allows you to avoid explicitly naming self, but requires cluttering your init signature
class MySecondClass {
var i: Int
var s: String
init(i _i: Int, s _s: String) {
i = _i
s = _s
}
}
MyFirstClass(i: 1, s: "hello")
MySecondClass(i: 1, s: "hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment