0
class AsyncOperation : NSOperation {
    override func main () {
        print("In the user queue")
        NSOperationQueue.mainQueue().addOperationWithBlock({
            print("main block")
        })
    }
}
let queue = NSOperationQueue()
let operation = AsyncOperation();
queue.addOperation(operation)

it prints In the user queue but does not print main block . Since I am adding to the main queue I expect it to get executed. Do i have to start the queue execution ??

Golak Sarangi
  • 809
  • 7
  • 22
  • 1
    I assume that this is a command-line program, and adding `dispatch_main()` should solve your problem, as explained in the linked-to thread. Otherwise let me know and I'll reopen the question. – Martin R Jun 17 '16 at 11:23
  • Yes I was trying it in playground. dispatch_main() worked. Thanks – Golak Sarangi Jun 17 '16 at 11:35
  • For playgrounds (and you might have mentioned that) there is also another solution: http://stackoverflow.com/questions/24058336/how-do-i-run-asynchronous-callbacks-in-playground: `XCPlaygroundPage.currentPage.needsIndefiniteExecution = true` – Martin R Jun 17 '16 at 11:42

0 Answers0