1.Instance variables that are pointers to other objects are called outlets. Methods that can be triggered by user interface objects are called actions.
2. this book, we discuss the following major types of projects:
-
Application: A program that creates windows.
-
Tool: A program that does not have a graphical user interface. Typically, a tool is a command line utility or a daemon that runs in the background.
-
Bundle or framework: A directory of resources that can be used in an application or a tool. A bundle (also called a plug-in) is dynamically loaded at runtime. An application typically links against a framework at compile time.
3.#import is similar to the C preprocessor's #include. However, #import ensures that the file is included only once. You are importing<Cocoa/Cocoa.h> because that includes the declaration of NSObject, which is the superclass of Foo.
Note that the declaration of the class starts with @interface. The @ symbol is not used in the C programming language. To minimize conflicts between C code and Objective-C code, Objective-C keywords are prefixed by @. Here are a few other Objective-C keywords: @end,@implementation, @class, @selector, @protocol, @property, and @synthesize.
4.Let's briefly discuss the chronology(年表) of an application: When the process is started, it runs the NSApplicationMain function, which creates an instance of NSApplication. The application object reads the main nib file and unarchives the objects inside. The objects are all sent the message awakeFromNib. Then the application object checks for events. The timeline for these events appears in Figure 2.26.
Figure 2.26. A Timeline
When it receives an event from the keyboard and mouse, the window server puts the event data into the event queue for the appropriate application, as shown in Figure 2.27. The application object 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 the application object checks its event queue for another event. This process of checking for events and reacting to them constitutes the main event loop.
Figure 2.27. 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.