swift结构体常量的存储属性

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.
相同的情况对于类却不同,因为类实例是引用类型。如果你把类实例赋值给一个常量的话,你依然可以改变他的变量属性的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值