O'Reilly logo

Pro Multithreading and Memory Management for iOS and OS X by Kazuki Sakamoto, Tomohiko Furumoto

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A

Example of ARC, Blocks, and GCD

Let’s see an example using ARC, Blocks, and GCD. The following source code reads data from a URL and displays the result on the main thread. That is a very typical use case in iOS applications so you can paste this as a part of your application. This shows you how ARC, Block, and GCD can be used for an application such as a twitter or Tumblr client.

The source code is explained with its comments.

NSString *url = @"http://images.apple.com/"     "jp/iphone/features/includes/camera-gallery/03-20100607.jpg"  /*   * On the main thread, downloading data from the specified URL starts asynchronously.   */ [ASyncURLConnection request:url completeBlock:^(NSData *data) {     dispatch_queue_t queue =         dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required