For the more curious: how selectors work

You learned in Chapter 20 that when you send a message to an object, the object’s class is asked if it has a method with that name. The search goes up the inheritance hierarchy until a class responds with Yeah, I have a method with that name.

Figure 27.4  The search for a method with the right name

The search for a method with the right name

As you can imagine, this search needs to happen very, very quickly. If the compiler used the actual name of the method (which could be very long), method lookup would be really slow. To speed things up, the compiler assigns a unique number to each method name it encounters. At runtime, it ...

Get Objective-C Programming: The Big Nerd Ranch Guide 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.