Posts

Showing posts from February, 2016

In Swift: NSBlockOperation and NSOperationQueue Sample

Let's first understand  Concurrency   which I am going to explain below:  Concurrency : It tells running several tasks in same time. So do some work on Main thread and on other thread at the same time, will come under concurrency. The iOS SDK and other way are there to achieve the same thing, but I have chosen  NSBlockOperation and NSOperationQueue . The  NSBlockOperation  class is a concrete subclass of  NSOperation  that manages the concurrent execution of one or more blocks. This is a very simple concept which I will explain in a very simple example.  There can be other use as well but I understood and used it in one scenario.  So, when you are doing some tasks, that tasks are taking time so you can use  NSOperationQueue   and NSBlockOperation queue if you don not want to involve Main Thread, as it is responsible for UI responsiveness. So if you are going to do a heavy operation  on Main Thread, which is taking time, user defiantly will stick in the UI