title: NSOperation property overrides (isExecuting / isFinished)
body: <p>I am subclassing <code>NSOperation</code> in Swift and need to override the <code>isExecuting</code> and <code>isFinished</code> properties since I am overriding the <code>start</code> method.</p>
  
  <p>The problem I run into is how to preserve key-value observing (KVO) while also being able to override these properties.</p>
  
  <p>Normally in Obj-C this would be rather easy to redeclare the properties as <code>readwrite</code> in the class extension <code>JSONOperation ()</code> definition. However, I don't see this same capability in Swift.</p>
  
  <p>Example:</p>
  
  <pre><code>class JSONOperation : NSOperation, NSURLConnectionDelegate
  {
      var executing : Bool
      {
          get { return super.executing }
          set { super.executing } // ERROR: readonly in the superclass
      }
  
      // Starts the asynchronous NSURLConnection on the main thread
      override func start()
      {
          self.willChangeValueForKey("isExecuting")
          self.executing = true
          self.didChangeValueForKey("isExecuting")
  
          NSOperationQueue.mainQueue().addOperationWithBlock(
          {
              self.connection = NSURLConnection(request: self.request, delegate: self, startImmediately: true)
          })
      }
  }
  </code></pre>
  
  <p>So here is the solution I have come up with, but it feels awfully ugly and hacky:</p>
  
  <pre><code>var state = Operation()
  
  struct Operation
  {
      var executing = false
      var finished = false
  }
  
  override var executing : Bool
  {
      get { return state.executing }
      set { state.executing = newValue }
  }
  
  override var finished : Bool
  {
      get { return state.finished }
      set { state.finished = newValue }
  }
  </code></pre>
  
  <p>Please tell me there is a better way. I know I could make a <code>var isExecuting</code> instead of the whole <code>struct</code>, but then I have two similarly named properties which introduces ambiguity and also makes it publicly writable (which I do not want).</p>
  
  <p>Oh what I would do for some access modifier keywords...</p>