Re: How to write better Swift


Quincey Morris
 

On Jul 8, 2017, at 17:15 , Jens Alfke <jens@...> wrote:

You can implement a property observer instead.

(Also to others suggesting will/didSet)

That doesn’t solve Gerriet’s problem. You can’t *prevent* setting the backing store without writing an actual setter. Similarly, if you want to constrain a value (e.g. keep an Int value >= 1), you can do it in didSet, but only at the cost of two writes to the backing store (which may have side effects).

Join cocoa@apple-dev.groups.io to automatically receive all group messages.