The best way to run code on a separate thread in iOS

In my opinion, the best way is with libdispatch (GCD). It limits you to iOS 4 and greater, but it’s just so simple and easy to use. The code to do some processing on a background thread and then do something with the results in the main run loop is incredibly easy and compact:

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
[self copyFromBundleToDocuments];
//
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
NSLog(@”Done!!”);
});
});
The best way to run code on a separate thread in iOS The best way to run code on a separate thread in iOS Reviewed by Unknown on 12:07 Rating: 5

No hay comentarios:

Con la tecnología de Blogger.