April 2012
Intermediate to advanced
196 pages
4h 42m
English
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, ...Read now
Unlock full access