Game Changing Mobility

Each day at our work consists of a sequence of tasks that fill our working hours. Same way, when you create an application, all the interface components (table views, UI controls, alerts, etc.) are run inside the main thread of your application. At some point in your application, you will want to populate these views with data. And this data can be retrieved from the disk, the web, a database, etc.

The issue that we face when we want to populate or handle huge amount of data is: ‘How would you efficiently load this data into your application interface while still allowing the user to have control of the application without any disturbance?’

Many applications in the app store simply ‘freeze’ while their application data is loaded. This will disappoint the user interaction. The secret to making apps without this problem is to move the unnecessary work (the activities which can take place without user interaction) to the background as possible. The iOS developer has two options here: Grand Central Dispatch And NSOperation. Let me explain about NSOperation here:

NSOperationQueue:

NSOperationQueue manages the concurrent execution of code operations in xcode. It acts as a priority queue, because operations are executed in a First-In-First-Out manner, with higher-priority (NSOperation.queuePriority) ones getting to the lower-priority ones.

NSOperation:

NSOperation is a single unit of work. It’s an abstract class that provides a useful, thread-safe structure for programming.NSOperation will perform network requests, text processing, or any other repeatable long-running task that produces associated state or data.

There is two different operations you can create, which are the prebuilt in once which are NSInvocationOperation and NSBlockOperation.

Priority

All operations may not be equally important. Setting the queuePriority property will promote or defer an operation in an NSOperationQueue according to the following rankings:

NSOperationQueuePriority

typedef enum : NSInteger {
NSOperationQueuePriorityVeryLow = -8,
NSOperationQueuePriorityLow = -4,
NSOperationQueuePriorityNormal = 0,
NSOperationQueuePriorityHigh = 4,
NSOperationQueuePriorityVeryHigh = 8
} NSOperationQueuePriority;
The following enumerated values are used to denote the priority of an operation. Operations are considered based on the priority.