Free Trial

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

Share this Page URL
Help

Chapter 13. Protocols > Summary - Pg. 262

262 Chapter 13 Protocols Note When you code a class that adopts an informal protocol, the protocol method implementations must go in the class's @implementation section, not in a category @implementation section. If you place the implementations in a separate category @implementation sec- tion, your method implementations are added to all classes (assuming the protocol is declared as a category on NSObject ). This is unlikely to be what you intended to do. So what's the point of using informal protocols? Before Objective-C 2.0, all the methods in a formal protocol were required. The only way to have optional methods in a proto- col was to use an informal protocol and note the optional methods in the documenta- tion. With the advent of @optional and @required , there isn't much reason to use an informal protocol: You can have optional methods and still enjoy the benefits of a formal protocol. You can see this progression in the Apple frameworks: In earlier versions of the AppKit, NSTableDataSource (the data source protocol for AppKit's NSTableView ) was an informal protocol. Beginning in Mac OS X Snow Leopard (v 10.6), NSTableDataSource has been replaced with the NSTableViewDataSource formal protocol.