Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 587
meaning-matters Avatar asked Oct 05 '16 07:10

meaning-matters


1 Answers

Try this:

self.myProperty = { self.myProperty }()
like image 67
Orkhan Alikhanov Avatar answered Nov 01 '22 07:11

Orkhan Alikhanov