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
Share this Page URL
Help

Chapter 7. The Class Object > Other Class Methods

Other Class Methods

The primary function of a class object is to act as a factory object to create instances of the class. As we saw in the previous chapter, you create object instances by using the class method alloc. The next two sections cover areas where classes often define additional class methods. Convenience constructors and singletons are common patterns in the Cocoa frameworks and you may want to use them in some of your own classes.

Convenience Constructors

Many of the Cocoa framework classes define convenience constructors, which combine allocation and initialization in a single method. The NSString class method string is a typical example. It returns an initialized, but empty string:


  

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