What if I want to assign a property to itself?

后端 未结 5 1803
孤街浪徒
孤街浪徒 2020-12-30 00:37

If I attempt to run the following code:

photographer = photographer

I get the error:

Assigning a property to itself

5条回答
  •  温柔的废话
    2020-12-30 01:41

    I hope one day #Swift developers will fix this miscuzzi :)

    Simple crutch:

    func itself(_ value: T) -> T {
        return value
    }
    

    Use:

    // refresh
    style = itself(style)
    image = itself(image)
    text  = itself(text)
    

    (optionals including)


提交回复
热议问题