Asking Questions about Classes

As you start working with variables that can contain objects from different classes, you might need to ask questions such as the following:

• Is this object a rectangle?

• Does this object support a print method?

• Is this object a member of the Graphics class or one of its descendants?

You can then use the answers to these questions to execute different sequences of code, avoid an error, or check the integrity of your program while it’s executing.

Table 9.1 summarizes some of the basic methods that the NSObject class supports for asking these types of questions. In this table, class-object is a class object (typically generated with the class method), and selector is a value of type SEL (typically created with ...

Get Programming in Objective-C, Fifth 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.