Hour 18. Extending a Class with Categories and Extensions

What You’ll Learn in This Hour

Differentiating Categories and Protocols

Choosing When to Use a Category

Comparing Categories and Subclasses

Building and Testing a Category

Comparing Categories and Protocols

In Hour 17, “Extending a Class with Protocols and Delegates,” you saw how to specify a set of methods for a protocol that can be adopted by any class. How the class that adopts the protocol implements it is up to that class: The protocol merely defines the methods that must be (somehow) implemented by the class. Accordingly, when a class adopts a protocol, it can assume that it can call the methods in that protocol.

Categories are somewhat similar to protocols. Instead of being ...

Get Sams Teach Yourself Objective-C in 24 Hours 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.