If you’ve been checking
your ~/Calculator
directory while stepping
through this chapter, you’ll probably have noticed
that several files were automatically created in it. This section
will discuss what these files contain and how they fit into a
project.
PB’s Groups & Files pane uses an outline view to list each project file by type, as shown in Figure 5-31. You can display the different types of files in this outline view by clicking the disclosure triangle next to a file type (e.g., Resources, Frameworks). In Table 5-1, we summarize what each file type means.
Table 5-1. Cocoa file types
File type |
Typical extensions |
Meaning |
---|---|---|
Classes |
|
Objective-C class interface ( |
Other Sources |
|
ANSI C ( |
Resources |
|
Resources used by the application, including the IB
( |
Frameworks |
|
Library files that are linked into your program (e.g., Cocoa and Foundation). |
Products |
|
Applications that have been built with PB. |
When you create a project, PB generates an Objective-C file called
main.m
containing the program’s
main( )
function. The main( )
function is where every Objective-C (and C) program begins.
The following code in the main.m
file is
generated in the Calculator project:
#import <Cocoa/Cocoa.h> int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); }
As you can see, this is a very simple function! All it does is run
the NSApplicationMain( )
function that is built
into the Cocoa Application Kit framework.
The Cocoa documentation for the NSApplication class (not function)
defines the NSApplicationMain( )
function as the following:
void NSApplicationMain(int argc, char *argv[]) { [NSApplication sharedApplication]; [NSBundle loadNibNamed:@"myMain" owner:app]; [NSApp run]; }
This function creates the NSApplication object, which creates the
autorelease memory pool that we discussed in Chapter 4, then loads the application’s
main nib file (MainMenu.nib
in Calculator) and
starts the NSApplication object’s main event loop.
The main event loop handles menu clicks, keystrokes, and all of the
other events to which an application can respond.
Control doesn’t return to main( )
until the NSApplication object receives a stop: or terminate: message, which usually happens in
response to a user’s choosing the
application’s Quit menu item. At that point, the
main( )
function receives the return code from the
NSApplicationMain( )
function.
In addition to creating the Objective-C
.h
, .m
,
.nib
, and main.m
program
files for a project, PB created the following files for us:
Calculator.pbproj
The directory containing the project files, which keep track of the
individual parts of the project. You might investigate this directory
in a Terminal window because, like
Calculator.app
, it appears to be a simple file
(not a folder) in the Finder.
Calculator.pbproj/project.pbxproj
The project file that keeps track of the parts of the project.
Calculator.pbproj/
username
.pbxuser
The project file that keeps track of the preferences for the user
username
.
English.lproj
A directory that contains the information for an English-language
version of our project, including the
MainMenu.nib
file (discussed earlier) in our
example.
English.lproj/InfoPlist.strings
A string table that references all of the strings inside the English-language project.
52.14.204.142