swiftpropertiesdidset

How to call didSet without changing property value


I need the code in didSet to be executed without changing the property's value.

Coming from Objective-C recently, there doesn't seem to be a setMyProperty().

So I tried:

self.myProperty = self.myProperty

which result in error Assigning a property to itself.

Because myProperty happens to be CGFloat, I could do:

self.myProperty += 0.0

which does trigger didSet and does not affect the value, but it doesn't show what I mean to do here.

Is there a way to call didSet in a more clear/direct way?


Solution

  • Try this:

    self.myProperty = { self.myProperty }()