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

Hour 8. Declaring Instance Variables in ... > Creating an Instance Variable for Cu...

Creating an Instance Variable for CurrencyConverter with a Superclass Name

There is a variation on the static typing example that you find frequently. In the previous example, the instance variable was statically typed with the class name—CurrencyConverter. You can statically type it as a class and then instantiate a subclass of that class. For example, you can declare the instance variable to be of class NSObject as shown in Figure 8.7.

Image

Figure 8.7. Declare the instance variable as type NSObject.

This means that you cannot send a display message to it because the compiler knows that display is not a method of NSObject.

You will come across issues like this, particularly in classes with a number of subclasses such as NSView and UIView. You frequently call methods of the superclass intending either to actually perform those methods or intending to perform code that overrides those methods in subclasses.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


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