title: Why use didSet when you can just mutate a variable and the value changes anyway?
body: <p>I read through this SO <a href="https://stackoverflow.com/questions/24006234/what-is-the-purpose-of-willset-and-didset-in-swift">didSet q&amp;a</a> and Apple’s <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-ID259" rel="nofollow noreferrer">Property Observers</a> and a few other posts. What I can’t seem to wrap my head around is what is the benefit of using didSet when mutating a variable when if you change the variable without using a property observer it’s going to change anyway?</p>
  
  <p>Scenario 1:</p>
  
  <pre><code>var someVal = 0
  
  someVal = 10
  
  // someVal now holds 10
  </code></pre>
  
  <p>Scenario 2:</p>
  
  <pre><code>var someVal: Int = 0{
  
      didSet{
      }
  }
  
  someVal = 10
  
  // again someVal now holds 10
  </code></pre>
  
  <p>Scenario 3:</p>
  
  <pre><code>var someVal: Int = 0{
  
      didSet{
  
         if someVal &gt; oldValue{
  
              someVal = newValue
         }
      }
  }
  
  someVal = 10
  
  // once again someVal holds a value of 10
  </code></pre>
  
  <p>The only thing I see in Scenario 3 is that if the condition isn’t met then someVal won’t change. But instead of adding it inside the didSet I can simply do this and the same exact thing will occur.</p>
  
  <pre><code>var someVal = 0
  
  var anotherVal = 10
  
  if someVal &lt; anotherValue{
       someVal = anotherValue
  }
  
  // once again someVal holds a value of 10
  </code></pre>
  
  <p>So other then adding a condition inside a didSet observer what is the benefit?</p>