July 2010
Beginner
416 pages
9h 51m
English
A protocol is a defined set of methods that a class can choose to implement. Protocols are useful when an object needs to talk to one or more other objects but doesn’t know (or particularly care) the class of those other objects. Objective-C protocols are the equivalent of Java interfaces. In fact, the designers of Java borrowed the concept from Objective-C. Protocols are used throughout the Cocoa frameworks. Objective-C has both formal and informal protocols. A formal protocol declares a set of required methods and perhaps some optional methods. A class can then adopt the protocol by implementing all the protocol’s required methods. When a class declares that it adopts a formal protocol, the compiler checks to see that the class ...