Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Using Blocks

In Objective-C 2.0, blocks refer to a language construct that supports “closures,” a way of treating code behavior as objects. First introduced to iOS in the 4.x SDK, Apple’s language extension makes it possible to create “anonymous” functionality, a small coding element that works like a method without having to be defined or named as a method.

This allows you to pass that code as parameters, providing an alternative to traditional callbacks. Instead of creating a separate “doStuffAfterTaskHasCompleted” method and using the method selector as a parameter, blocks allow you to pass that same behavior directly into your calls. This has two important benefits.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial