O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Mikey Ward, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required