O'Reilly logo

Effective Objective-C 2.0: 52 Specific Ways to Improve Your iOS and OS X Programs by Matt Galloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4. Protocols and Categories

Protocols are a language feature similar to interfaces in Java. Objective-C does not have multiple inheritance, so protocols provide a way to define a set of methods that a class should implement. Protocols are most often used in implementing the Delegate pattern (see Item 23), but there are other uses as well. Getting to know them and using them can make code a lot more maintainable, as they are a good way of documenting an interface to your code.

Categories too are an important language feature of Objective-C. They provide a mechanism for adding methods to a class without having to subclass it as you would have to in other languages. This feature is made possible by the highly dynamic nature of the runtime but also ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required