swift手册:
it is not possible to change the value type instance property, even though the instance is a variable property.
This behavior is due to structures being value types. When an instance of a value type is marked as a constant, so are all of its 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.
意思是一个struct类型的常量,其属性值不可改变;如果是struct类型的变量,其属性可变。
网友评论