
Previous chapters talk about design principles in general, as well as about the specific iPhone developer tools (Xcode, Interface Builder) available to you. Chapter 5, for example, has you create the skeleton for a fully functioning iPhone application (my ReturnMeTo jewel) — and now you get to flesh it all out with the code necessary for transforming the ReturnMeTo application from something that just sits there and looks pretty to something that actually does something.
A quick refresher peek at Chapter 5 will show you that quite a bit of the ReturnMeTo application is already in place and ready to go. If you click the text field, for example, you do get the keyboard — though you can’t do
Anything with it just yet. Both the text field and the label are automatically created from the nib file — which is great — but somehow you have to accomplish two tasks:
✓ Get what the user enters into the text field.
✓ Display the user input in the label you created.
In effect, you have to connect things up so the left hand knows what the right hand is doing.
Fortunately, the framework was designed to allow you to do this easily and gracefully. The view controller can refer to objects created from the nib file by using a special kind of instance variable (a variable defined as part of a class, with each object of that class having its own copy) referred to as an Outlet. If I want (for example) to be able to access the text field object in my ReturnMeTo application, I take two steps:
1. Declare an outlet in my code.
2. Use Interface Builder to point the outlet to the text field I created earlier.
Then, when my application is initialized, the text field outlet is automatically initialized with a pointer to the text field. I can then use that outlet from within my code to get the text the user entered in the text field.
The fact that a connection between an object and its outlets exists is actually stored in a nib file. When the nib file is loaded, each connection is reconstituted and reestablished — thus enabling you to send messages to the object. iBOutlet is the keyword that tags an instance-variable declaration so the Interface Builder application knows that a particular instance variable is an outlet — and can then enable the connection to it with Xcode.
£
In my code, it turns out I need to create two outlets — one to point to the text field and one to point to the label where I will display the number the user enters. To get this outlet business started, I need to declare it, which I do with the help of the aforementioned iBOutlet keyword.
Okay, I’m guessing you realize that declaring something in programming doesn’t involve standing on a soapbox in Hyde Park and saying something at the top of your lungs. Declaring something code-wise involves. . . writing code. (Y ou knew that.) More specifically, in iPhone application development, declaring something code-wise involves writing code using the Xcode editor — which leads us right to the next section.

Congratulations — you have just gone through the "Classic Comics" version of another several hundred pages of Apple documentation, reference manuals, and how-to guides.
Various events besides termination can interrupt your application to allow the user to respond — for example, incoming phone calls, SMS messages, calendar alerts, or the user pressing the Sleep button on an iPhone. Such interruptions may only be temporary. If the user chooses to ignore an interruption, your application continues running as before. If the user decides to answer the phone or reply to an SMS message, however, your application will be terminated.
Launch, initialize, process, terminate, launch, initialize, process, terminate. . . it has a nice rhythm to it, doesn’t it? And those are the four major stages of the application’s life cycle. But life isn’t simple — and neither is runtime. To mix things up a bit, your application will also have to come to terms with interruptions and memory management.
Getting stuff to (safely) shut down is another application delegate responsibility. To handle termination, the application delegate implements the delegate method applicationWillTerminate: to save any unsaved data or key application state (where the user is in the application — the current view and stuff like that) to disk. (Okay, I know, the disk in the iPhone is not really a disk; it’s a solid state drive that Apple calls a disk, but if it calls it that, I probably should, too, just so I don’t confuse too many people.). You can also use this method to perform additional cleanup operations, such as deleting temporary files.
After a user launches your application, the functionality provided in the UIKit framework manages most of the application’s infrastructure. Part of the initialization process mentioned in the previous section involves setting up the main run loop and event handling code, which is the responsibility of
The next step is for the UIApplication to send the ReturnMeToApp Delegate applicationDidFinishLaunching: message. Step 5 in Figure 6-6 represents what happens when the applicationDidFinish Launching: method is invoked.