Posts

Showing posts with the label Concurrency

Copy Vs Mutable Copy in iOS

It's found very confusing for most of the folks, who is not having much experience in Objective-C. Before starting I just to say: Just remember below lines- 1 - copy always creates an immutable copy means you can not modify the object. 2 - mutableCopy always creates a mutable copy  means you can modify the object Here onwards I try to explain copy and mutable copy with some examples: copy: NSArray *obj = [ NSArray arrayWithObjects : @"1" , @"2" , nil ]; NSArray *copyObj = [obj copy ]; NSArray *mutableObj = [obj mutableCopy ]; When you try to see the details of copyObj its clearly shows  __NSArrayI which tells that you can not modify this object Printing description of copyObjy: ( 1, 2 ) Same way  When you try to see the details of mutableObj its clearly shows  __NSArrayM which tells that you can modify this object Printing description of mutableObjy: ( 1, 2 ) As the copyObj is ass...

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 M...