Customizing the Behavior of Framework Classes

Although you’ll be creating classes of your own (especially model classes), often you’re going to want to customize the behavior of a particular framework class. There are three ways to go about it:

check.png Subclassing

check.png Delegating

check.png Declared properties

In this section I’ll cover the first two, and the third in the following section.

Subclassing

Objective-C, like other object-oriented programming languages, permits you to base a new class definition on a class already defined. The base class is called a superclass; the new class is its subclass. The subclass is defined only by its extension to its superclass; everything else remains the same. Each new class that you define inherits methods and instance variables of its superclass.

Some framework classes are expected to be subclassed. Among them are view controllers, which you’ll be subclassing quite a bit. Others aren’t expected to be subclassed because you’re going to need to customize their behavior; in those situations, you use delegation instead.

The Delegation pattern

Delegation is a pattern used extensively in the iOS frameworks, so much so that, if you want to do any serious app development ...

Get iPad Application Development For Dummies, 3rd Edition 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.