Online Book Reader

Home Category

Objective-C Programming_ The Big Nerd Ranch Guide - Aaron Hillegass [33]

By Root 421 0
from the editor where you’re writing code to the wellspring of knowledge in the documentation. Close the Organizer and return to your DateList project.

In main.m, find the line that includes [dateList addObject:now]. Hold down the Option key and click on addObject:. The Quick Help window will appear with the information about that method:

Figure 16.5 Quick Help window

Notice that there are links in the Quick Help window. If you click a link, it will open the appropriate documentation in the Organizer. Handy, right?

If you want to see that Quick Help all the time, you can open it as a pane in Xcode.

In the upper-right corner of the Xcode window, find a segmented control called View that looks like and indicates Xcode’s lefthand, bottom, and righthand panes. Selecting and de-selecting these buttons will hide and show the respective panes.

The lefthand pane, which you’ve used plenty by now, is called the navigator. The bottom pane, which you’ve also seen, includes the console and is called the debug area. The righthand pane is called Utilities. Click the righthand View button to reveal Utilities. At the top of Utilities, click the button to reveal the Quick Help pane.

This pane will show help for the text selected in the editor. Try it: just select the word “NSMutableArray” in the editor:

Figure 16.6 Quick Help pane

Note that when you select something else, the Quick Help pane will immediately update to show the documentation for the new selection.

Other options and resources


If you Option-double-click on any text, the Organizer will search for that string.

If you Command-click on any class, function, or method, Xcode will show you the file where it is declared. (Try Command-clicking the word “NSMutableArray”.)

Figure 16.7 The declaration of NSMutableArray

If there are several declarations that match, you’ll get a pop-up when you Command-click. Try Command-clicking addObject:.

From time to time, Xcode will call back to the mothership to see if there is any updated documentation. It will download the updates and re-index them for easy searching. You can trigger an immediate check for updates in the preferences panel for Xcode.

Apple hosts a collection of discussion mailing lists at http://lists.apple.com/, and several of them are devoted to developer topics. If you can’t find an answer in the docs, try searching the archives of the lists. (As a courtesy to the thousands of people on each list, please search the archives carefully before posting a question.)

There is one more resource that you should know about: stackoverflow.com. This website is a very popular place where programmers ask and answer questions. If you can think up a few keywords that describe the sort of problem you are having, you can probably find an answer there.

17

Your First Class


So far, you have only used classes created by Apple. Now you get to write your own class. Remember that a class describes objects in two ways:

methods (both instance methods and class methods) implemented by the class

instance variables within each instance of the class

You’re going to write a Person class, similar to the struct Person you wrote in Chapter 10. Your class will be defined in two files: Person.h and Person.m. Person.h, known as the header or interface file, will contain the declarations of instance variables and methods. Person.m is known as the implementation file. This is where you write out the steps for, or implement, each method.

Create a new project: a Foundation Command Line Tool named BMITime.

To create a new class, select File → New → New File.... From the Mac OS X section on the left, select Cocoa and choose the Objective-C class template. Name your class Person and make it a subclass of NSObject. Finally, make sure the BMITime target is checked and click Save.

Notice that the new class files, Person.h and Person.m, now appear in the project navigator. Open Person.h. Declare two instance variables and three instance methods:

#import

// The

Return Main Page Previous Page Next Page

®Online Book Reader