title: What is the purpose of willSet and didSet in Swift?
body: <p>Swift has a property declaration syntax very similar to C#'s:</p>
  
  <pre><code>var foo: Int {
      get { return getFoo() }
      set { setFoo(newValue) }
  }
  </code></pre>
  
  <p>However, it also has <code>willSet</code> and <code>didSet</code> actions. These are called before and after the setter is called, respectively. What is their purpose, considering that you could just have the same code inside the setter?</p>