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
  • PrintPrint

Using Protocols

Like classes, protocols in Objective-C are objects. The behavior of protocols was one of the things that Apple changed with the modern runtime. Previously, protocols were identified by name, and two protocols were considered equivalent if they had the same name. This meant that if you had two protocols with the same name declared in different libraries, you couldn’t tell which of them an object implemented. More importantly, you couldn’t look up a protocol and see what methods it required.

With Objective-C 2, protocols are now unique. You can now get a protocol by name and inspect it. This sometimes worked with the old model, but it depended on whether the compiler had already emitted a full definition of it.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint