title: Asynchronous Callback in NSOperation inside of NSOperationQueue is never called
body: <p>I need to chain together several <code>NSOperation</code>s that do network calls in one <code>NSOperationQueue</code> and then wait for all to be completed. </p>
  
  <p>I'm adding all of the <code>NSOperation</code>s to my <code>NSOperationQueue</code> and then call <code>operationQueue.waitUntilAllOperationsAreFinished()</code>. This works, but it waits indefinitely, as the callbacks in the <code>NSOperations</code>, that set the operation's state to 'finished', get never called.</p>
  
  <p>I'm using the following <code>NSOperation</code> subclass:</p>
  
  <pre><code>class ConcurrentOperation: NSOperation
  {
      enum State: String
      {
          case Ready, Executing, Finished
  
          private var keyPath: String
          {
              return "is" + self.rawValue
          }
      }
  
      var state: State = State.Ready {
          willSet (newValue)
          {
              self.willChangeValueForKey(newValue.keyPath)
              self.willChangeValueForKey(self.state.keyPath)
          }
  
          didSet
          {
              self.didChangeValueForKey(oldValue.keyPath)
              self.didChangeValueForKey(self.state.keyPath)
          }
      }
  }
  
  extension ConcurrentOperation
  {
      override var ready: Bool {
          return super.ready &amp;&amp; self.state == .Ready
      }
  
      override var executing: Bool {
          return self.state == .Executing
      }
  
      override var finished: Bool {
          return self.state == .Finished
      }
  
      override var concurrent: Bool {
          return true
      }
  
      override var asynchronous: Bool {
          return true
      }
  }
  
  extension ConcurrentOperation
  {
      override func start()
      {
          if self.cancelled
          {
              self.state = .Finished
              return
          }
  
          self.state = .Executing
          self.main()
      }
  
      override func cancel()
      {
          self.state = .Finished
      }
  }
  </code></pre>
  
  <p>This is based on a Raywenderlich Tutorial and <a href="https://gist.github.com/calebd/93fa347397cec5f88233" rel="nofollow">https://gist.github.com/calebd/93fa347397cec5f88233</a> . </p>
  
  <p>What this should do is tell the NSOperationQueue that only when the <code>main()</code> method in a subclass of <code>ConcurrentOperation</code> sets the state to <code>.Finished</code> it is completed. <strong>And this is also fulfilled by the operation.</strong> </p>
  
  <p><em>However</em>, If I construct the following <code>main()</code> method in such a <code>ConcurrentOperation</code> subclass, the <code>NSOperationQueue</code> never stops as the <strong>asynchronous part is never called</strong>:</p>
  
  <pre><code>override func main()
  {
      dispatch_async(dispatch_get_main_queue(), {
          sleep(1)
          self.state = .Finished  // never called!
      })
  }
  </code></pre>
  
  <p>The problem is the same with a Firebase-Query Callback that I use in my app. </p>
  
  <p>I tried to override the <code>concurrent: Bool</code> property and return <code>true</code>, but that doesn't fix it neither. </p>
  
  <p>How can I accomplish that asynchronous tasks are actually executed in my <code>ConcurrentOperation</code> subclass' <code>main()</code> method?</p>
  
  <p>Thank you!</p>