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?
答案 0 :(得分:4)
在此Swift Guide style中,您可以找到类似的参考:
private var centerString: String {
return "(\(x),\(y))"
}
在The swift Programming Language book (swift 4 beta)(链接到)中,您还可以找到以下示例:
第812页:
private var privateInstance = somePrivateClass()
第822页:
private var privateVariable = 12
摘自:Apple Inc.“Swift编程语言(Swift 4 beta)。”iBooks。
我确实认为第二种选择是正确的方法。