Chapter 8. Dynamic typing and runtime type information
This chapter covers
Objective-C is a class-based object system in which each object is an instance of a particular class. At runtime, each object is aware of its class by way of a pointer named isa that points to a Class object (take a look in the debugger window the next time you’re stuck at a breakpoint, and you should see isa listed in the variable window). The class object describes the data requirements for an instance of the class and its behavior in the form of the instance methods it implements.
Objective-C is also an inherently dynamic environment. As many decisions as possible are delayed until runtime rather than made during compile time. For example:
- Objects are dynamically allocated (via class methods such as alloc).
- Objects are dynamically typed. Any object can be referenced by a variable of type id. The exact class of the object and therefore the particular methods it provides aren’t determined until runtime, but this delay doesn’t stop code that sends messages to those objects from being written.
- Messages are dynamically bound to methods. A runtime procedure matches the method selector in a message with a particular method implementation that “belongs to” the receiver object. The mapping can change or be modified dynamically to change the behavior of the application and to introduce aspects such as logging without recompilation.