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, ...
Get Pro Multithreading and Memory Management for iOS and OS X 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.