Friday, April 13, 2012

iOS and Threads

While watching the Free Stanford Class Videos About iOS, iPhone, iPad, Objective-C and Xcode, I came across the Blocks and Multithreading lecture.

It does a great job of describing how to avoid locking up the user interface (iPhone or iPad) while the application needs to do something that is time intensive.

In general, one would call the following things in their proper context.

    dispatch_queue_t downloadQueue = dispatch_queue_create("widget download", NULL);
    dispatch_async(downloadQueue, ^{
        NSArray *fetchedWidgets = [KTWidgetFetcher widgets];
        NSLog(@"done fetching widgets");

        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"UI update is happening");
            self.widgets = fetchedWidgets;

Fun stuff!

No comments:

Post a Comment