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

Chapter 3: Giving Your App Something to Do > Creating a Tip Calculator

Creating a Tip Calculator

Here’s where I demonstrate the interaction between the UI and the code through a very simple example: I turn SimpleCocoaWindowApp (as demonstrated in Chapter 2) into a tip calculator with the following steps.

1. Select SimpleCocoaWindowAppAppDelegate.h in the Project navigator.

This is the header file for our class, and it looks pretty bare-bones. The header file contains declarations of the parts of a class — this file can be #imported into other source modules as a “promise” of what the class provides. You’re going to add some UI controls to the window, and this is the place to do it.

2. Enter the purple-colored text shown in Listing 3-1.

I’m going to use purple to highlight the new code to add. You’re adding four member variables and one new method. The member variables are added between the braces of the @interface declaration — this tells Xcode where to find the data portion of your class. The method is added after the braces surrounding the member variables — this tells Xcode where to find the functions that operate on the data of your class. I will explain in the next section what the different parts of the items you just added are.


  

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


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