Chapter 12
Categories
When you write object-oriented programs, you'll often want to add some new behavior to an existing class: you can always create new hoops for objects to jump through. For example, you might have designed a new kind of tire, so you'd subclass Tire
and add the new cool stuff. When you want to add behavior to an existing class, you'll often create a subclass.
But sometimes, subclassing isn't convenient. For example, you might want to add some new behavior to NSString
, but you remember that NSString
is really the front end for a class cluster, which makes it difficult to subclass. In other cases, you might be able to make a subclass, but you're using a toolkit or library that won't be able to handle objects of the new class. ...
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.