IOS swift if let a = b 可以通过a改变b的值么?,请大神解释解释
巴扎黑
巴扎黑 2017-04-17 17:53:47
0
4
236

如图为啥,为啥显示是这不科学呢,我觉得应该显示科学才对,莫非label和myLabel是绑定在一起的?

巴扎黑
巴扎黑

reply all(4)
刘奇

The class in Swift is a reference type, which is actually a pointer. label and myLabel point to a memory address, so they change the same thing
It’s just that the pointer myLabel cannot change the address it points to
You can try myLabel == = label to determine whether the addresses are the same

Ty80

labelmyLabel 引用的是同一个对象,label.text = “xx”myLabel.text = “yy” 都是设置那个对象的 text Properties.

Peter_Zhu

In Swift, all transfers of value types are copies, and all transfers of reference types are addresses

左手右手慢动作

Thank you to the three great people above.
struct and enum are value types (pass by copy value) class instance objects are reference types (pass pointer)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template