class
X {
private
var a: Int
private
var b: String
init() {
a = 0
b =
""
}
}
class
ViewController: UIViewController {
override func viewDidLoad() {
super
.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var x = X()
x.a = 100
x.b =
"Hello"
}
}
在Swift中,private成員不單單被當前類,並且能被在當前swift源文件的任何做用域被訪問。可是在其它Swift源文件中就沒法訪問了。
Swift中對訪問權限設置得比較鬆弛。swift