A message is the name of a method, and any parameters associated with it, that are sent to, and executed by, an object. To get an object to do something, you send it a message telling it to apply a method. In Objective-C, you specify the object (known as the receiver of the method) and the message being sent to that object by enclosing the message expression in brackets. For example, this message expression tells the myRectangle object to perform its display method:

[myRectangle display];

(The expression is followed by a semicolon (;) as is normal for any line of code in C.)

The method name in a message serves to select a method implementation—when a message is sent, the runtime system selects the appropriate method from the receiver’s repertoire and invokes it. For this reason, method names in messages are often referred to as selectors.

Methods can also take parameters, also called arguments. A message with a single argument affixes a colon (:) to the selector name and puts the parameter right after the colon. This construct is called a keyword; a keyword ends with a colon, and a parameter follows the colon. A method that takes multiple parameters has multiple keywords, each followed by a colon.

[myRectangle setLineWidth:0.25];
[myRectangle setWidth:20.0 height:50.0];

Prerequisite Articles