Quick glance at NSOperationQueue

I was recently having a quick play with threading in COCOA ( because I needed to run some code on another thread ) and stumbled across NSOperationQueue within the docs. Basically, NSOperationQueue handles NSOperation’s, you give it an NSOperation, it will queue it, and run it when it gets to that part in the queue, but the cool thing is … it runs the NSOperation on another thread!

Its really simple to use, to run your own code / class, you ust subclass NSOperation and have a method called main which doesn’t return anything, so … – (void)main {}. main will get invoked when the item gets called, once all your code has done what it was set out to do, you simple have to perform a selector on the main thread and do what ever you like.

All that said and done, its pretty god damn awesome!, if you haven’t had a look at it yet, its worth a go :D.

Leave a comment

You must be logged in to post a comment.