Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Dot Syntax

We should mention an alternative syntax for sending accessor messages to an object called dot syntax:

// Following two lines are exactly equivalent
int value = [item valueInDollars];
int value = item.valueInDollars;

// Following two lines are exactly equivalent
[item setValueInDollars:5];
item.valueInDollars = 5;

We have reservations about Objective-C newcomers using dot syntax. We think it hides the fact that you are actually sending a message and can be confusing. Once you are comfortable with Objective-C, it is totally okay to use dot syntax. But while you are learning, it’s better to use square brackets to make sure you understand what is really going on.

This book will always use square brackets for sending accessor messages.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint