5. Messaging

In Objective-C, when you want an object to do something, you send the object a message, and in response, the object executes one of its methods. This is not quite the same thing as calling a function. Functions are usually statically bound—the code that the function executes is determined when the program is compiled. Using messaging, the actual code that is executed in response to a message is determined at execution time.

In this chapter, you will learn how Objective-C messaging works. The chapter covers methods, message expressions, and the machinery of the messaging system.


The structure of an Objective-C method is very similar to that of a C function (in fact, the compiler eventually turns the methods into C functions). ...

Get Learning Objective-C 2.0: A Hands-On Guide to Objective-C for Mac and iOS Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.