在
Swift中,我们用let表示一个不可变的变量.
我不明白的是你改变他们的属性的原因.例如:
let lbl = UILabel() lbl.textAlignment = .Right()
为什么要更改textAlignment?通过改变属性,我们还没有改变应该是常量的变量lbl吗?
根据
Swift Programming Language,常量结构的属性也是常量,但常量类可以具有可变属性.
用他们的话说,
If you create an instance of a structure and assign that instance to a constant,you cannot modify the instance’s properties,even if they were declared as variable properties…
The same is not true for classes,which are reference types. If you assign an instance of a reference type to a constant,you can still change that instance’s variable properties.