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

20.7. Remember the Superclass

One of the great features of object-oriented programming is the fact that it has a hierarchical structure. This has a wonderful benefit — inheritance. Because every class in Cocoa (with the exception of NSObject) is a subclass of some other class (or classes) above it in the class hierarchy, every class has more methods than those listed for its particular type. This can be confusing at first for some beginners.

Consider this example. The NSTextField and NSTextView controls in Cocoa seem like they should work in a similar fashion because they both display text. By taking a quick look at the documentation, however, you find that they're very different controls. The NSTextView control doesn't have a method for setting its text. The documentation for NSTextView shows that it's a subclass of NSText. NSText, on the other hand, does have a method for setting the text of the view: setString. You may be tempted to use the setString method with an NSTextField control. It's a good guess but an incorrect one.


  

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