CHAPTER 27

image

Background Processing

Background Processing Defined

When your program needs to do more than one thing at a time, you can use background processing. Background processing in Objective-C is done with a Foundation class called NSOperationQueue.

NSOperationQueue manages lists of operations and decides how to schedule the resources needed to run an operation. Operations are blocks of code. Operations can execute simultaneously or one at a time.

Let’s say that you want to count to 10,000 while printing this out to the log. To do this, you would code something like the following:

for (int y=0; y<=10000; y++) {    NSLog(@"y = %i", y);}

This ...

Get Objective-C Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.