I've seen underscore used as a prefix for private properties
private var _aPrivateVar: String = "I am private"
I've seen them not used
private var aPrivateVar: String = "I am private"
Syntactically, it makes no difference and my preference is to not use them. However, what's the accepted convention in Swift so that I pick the right habit up?
In this Swift Guide style, you can find a similar reference:
private var centerString: String {
return "(\(x),\(y))"
}
In The swift Programming Language book (swift 4 beta) (link to ), you can also find these examples:
page 812:
private var privateInstance = somePrivateClass()
page 822:
private var privateVariable = 12
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 4 beta).” iBooks.
I do believe that the second option is the correct way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With