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
  • DownloadDownload
  • PrintPrint

5.3. Accessors

All instance variables are protected in Objective-C by default, so you should always use accessors to get and set values. You should even use them when getting and setting values within the object itself. This is partially just because it’s better encapsulation, but the other reason is that Cocoa offers some more advanced “generic programming” features that depend on using accessors properly. Here’s an example of using accessors for the caption instance variable:

[photo setCaption:@"Day at the Beach"];
currentCaption = [photo caption];


  

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