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

Extensions

Suppose you’re writing a class that other programmers will use. You’d like to have some methods that are for your internal use only. If you declare the methods in your class’s header file, they will be visible to anyone using the class. Extensions let you declare methods—out of public view—by adding an interface section in the class’s implementation file. (Extensions extend the interface declaration into the .m file.)

A common use for extensions is to provide an internal setter method for an instance variable that you want to be publicly read-only. Listing 11.3 shows the header file for a class like that. The class declares a getter for the instance variable readOnlyBool, but it does not declare a setter method. This makes readOnlyBool effectively a read-only variable (at least for those who do not go snooping; see Security, later in this chapter).


  

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