title: Swift: Why does a variable with a setter must also have a getter?
body: <p>Quick question: <em>why?</em></p>
  
  <hr>
  
  <p>Context: </p>
  
  <p>Am using <a href="https://github.com/Swinject/Swinject" rel="noreferrer">Swinject</a> dependency injection to add <strong>small-s</strong> singleton model classes to my views thus:</p>
  
  <pre><code>defaultContainer.registerForStoryboard( MyViewController.self )
  {
      responder, viewController in
      viewController.proxy = responder.resolve( MyProxy.self )!
  }
  </code></pre>
  
  <p>I want to guard against the risk of accidentally overwriting this singleton instance by using a computed property thus:</p>
  
  <pre><code>private var _proxy: MyProxy!
  
  var proxy: MyProxy 
  { 
      set { if _proxy == nil { _proxy = newValue } } 
  }
  </code></pre>
  
  <p>But. I can't. Because I <em>must</em> also declare a getter.</p>
  
  <p><em>Frustrating!</em></p>
  
  <p>For now I am using the following hack. But really...</p>
  
  <pre><code>var proxy: MyProxy?
  {
      get { return nil }
      set { if _proxy == nil &amp;&amp; newValue != nil { _proxy = newValue } }
  }
  </code></pre>