title: Swift/iOS: using computed property to trigger UI update, which is better: didSet, willSet or set?
body: <p>The UI in my iOS app is complex enough that I sometimes get confused when I should enable/disable/hide/show some buttons or views. After some thoughts, I think the app has only three states: <strong>Idling</strong>, <strong>Recording</strong>, and <strong>Playing</strong>. </p>
  
  <p>So I created a computed property variable of the enum type <code>AppState</code>, through which I wish to observe the state changes so I can update the UI accordingly. Some of the UI changes include showing or disabling buttons as well as removing custom <code>UIView</code> objects from their super views.</p>
  
  <pre><code>var curState : AppState = .Idling {
      didSet {
            if newValue != oldValue {
              updateUI() // ?? better here?
            }
      }
      willSet(newValue) {
           updateUI() // ?? good here?
      }
     set {
           updateUI() // ?? good here
      }
  }
  </code></pre>
  
  <p>I have been using the <code>set</code> above to call <code>updateUI()</code> method, it works fine, but I would like to know which of the three observers is better? I haven't tried <code>willSet</code> or <code>didSet</code>, but I am leaning towards using <code>didSet</code> for the reason that I can compare the <code>oldValue</code> and <code>newValue</code> before updating UI. I could be wrong, I am all ears for advice here. </p>
  
  <p>Thanks!</p>