- In Xcode
- In Interface Builder
- Back in Xcode
- Documentation
- What Have You Done?
What Have You Done?
You have now gone through the steps involved in creating a simple Cocoa application:
-
Create a new project.
-
Lay out an interface.
-
Create custom classes.
-
Connect the interface to your custom class or classes.
-
Add code to the custom classes.
-
Compile.
-
Test.
Let's briefly discuss the chronology of an application: When the process is started, it runs the NSApplicationMain function. The NSApplicationMain function creates an instance of NSApplication. A global variable called NSApp points to that instance of NSApplication. NSApp reads the main nib file and unarchives the objects inside. The objects are all sent the message awakeFromNib. Then NSApp checks for events. The timeline for these events appears in Figure 2.32.
Figure 2.32 A Timeline
When the window server receives an event from the keyboard and mouse, it puts the event data into the event queue for the appropriate application, as shown in Figure 2.33. NSApp reads the event data from its queue and forwards it to a user interface object (like a button), and your code gets triggered. If your code changes the data in a view, the view is redisplayed. Then NSApp checks its event queue for another event. This process of checking for events and reacting to them constitutes the main event loop.
Figure 2.33 The Role of the Window Server
When the user chooses Quit from the menu, NSApp is sent the terminate: message. This ends the process, and all your objects are destroyed.
Puzzled? Excited? Move on to the next chapter so we can fill in some blanks.