swift结构体常量的存储属性

来源:互联网 发布:电路图画图软件有几种 编辑:程序博客网 时间:2024/06/04 18:46

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:
如果你创建一个结构体实例并且把实例赋值给一个常量,你不能够修改这个常量的属性,即使这些属性是变量。
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.
相同的情况对于类却不同,因为类实例是引用类型。如果你把类实例赋值给一个常量的话,你依然可以改变他的变量属性的值。

0 0
原创粉丝点击