Chapter 13

Protocols

in the previous chapter, we talked about the magic of categories and informal protocols. When you use an informal protocol, as you saw in Chapter 12, you implement only the methods you want to respond to. For the NSNetServiceBrowser delegate in Chapter 12, we implemented only the two methods that get called when a new service is added to or removed from the network: we didn't have to implement the six other methods in the NSNetServiceBrowserDelegate informal protocol. We also didn't have to declare anything in our object saying that we're usable as an NSNetServiceBrowser delegate. It all just worked with a minimum of fuss.

As you might guess, Objective-C and Cocoa also include the concept of a formal protocol, and in this ...

Get Learn Objective-C on the Mac 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.