In Swift, does resetting the property inside didSet trigger another didSet?

前端 未结 3 875
南方客
南方客 2020-12-29 07:17

I\'m testing this and it appears that if you change the value within didSet, you do not get another call to didSet.

var x: Int = 0         


        
3条回答
  •  青春惊慌失措
    2020-12-29 07:58

    It'll work just fine, but it seems pretty like a pretty bad idea from the standpoint of a consumer of your API.

    It doesn't recurse, the way I suspected it might, so that's good at least.

    I can think of few cases in which it would be acceptable for a setter to change what i'm setting. One such example might be a variable that's set to an angle, which is automatically normalized to be [0, 2π].

提交回复
热议问题