search

Home  >  Q&A  >  body text

IOS swift if let a = b 可以通过a改变b的值么?,请大神解释解释

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

巴扎黑巴扎黑2889 days ago244

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:55:47

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:55:47

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:55:47

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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:55:47

    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)

    reply
    0
  • Cancelreply