title: Swift - Custom setter on property
body: <p>I am converting a project in to Swift code and have come across an issue in a setter. My Objective-C code looked like this:</p>
  
  <pre><code>- (void)setDocument:(MyDocument *)document
  {
      if (![_document isEqual:document]) {
          _document = document;
  
          [self useDocument];
      }
  }
  </code></pre>
  
  <p>and allowed my View Controller to run this each time the document was set (typically in the <code>prepareForSegue:</code> method of the presenting View Controller).</p>
  
  <p>I have found the property observers <code>willSet</code> and <code>didSet</code> but they only work when the property is being updated, not when it’s initialised and updated.</p>
  
  <p>Any ideas? Thanks</p>
  
  <p>UPDATE</p>
  
  <p>after trying get{} and set{} I get the <code>EXC_BAD_ACCESS</code> error</p>
  
  <pre><code>var document: UIDocument? {
      get {
          return self.document!
      }
      set {
          self.document = newValue
  
          useDocument()
      }
  }
  </code></pre>