私有财产的命名约定 [英] Naming convention for Private Properties
问题描述
我已经看到下划线用作私有属性的前缀
I've seen underscore used as a prefix for private properties
private var _aPrivateVar: String = "I am private"
我看过他们没用过
private var aPrivateVar: String = "I am private"
从语法上讲,这没有什么区别,我的首选项是不使用它们.但是, Swift 中接受的约定是什么,以便我养成正确的习惯?
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:
第812页:
private var privateInstance = somePrivateClass()
第822页:
private var privateVariable = 12
摘录自:Apple Inc."Swift编程语言(Swift 4 beta)." iBooks.
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.
这篇关于私有财产的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!