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
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)
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
label
和myLabel
引用的是同一个对象,label.text = “xx”
和myLabel.text = “yy”
都是设置那个对象的text
Properties.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)