Methods and messages

Methods are like functions. They contain code to be executed on command. In Objective-C, to execute the code in a method, you send a message to the object or class that has that method.

The NSDate class has a date method. In the code you just wrote, you sent the date message to the NSDate class to execute the date method.

N​S​D​a​t​e​ ​*​n​o​w​ ​=​ ​[​N​S​D​a​t​e​ ​d​a​t​e​]​;​

This was your first message send.

Message sends

A message send is surrounded by square brackets and has two parts: the receiver and the selector.

Figure 13.3  A message send

A message send

What does sending the date message ...

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.