Created
April 2, 2015 15:33
-
-
Save wjlafrance/296c9321eb8dce253303 to your computer and use it in GitHub Desktop.
Init argument naming conventions
This file contains hidden or 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
// 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