Learn Objective-C on the Mac - Mark Dalrymple [15]
Inside Release, and you will find two files. One, called Hello World or Hello World.app (depending on your Finder preferences) is your brand-spanking-new application.
Congratulations. You’re a developer. That’s a full-fledged application you’re looking at, just like all the ones in your Applications folder. You can e-mail it to your Aunt Bessie or your best friend to show off the fact that you are now a bona fide Mac OS X application developer. Don’t worry about the other file in this folder. It’s something called a symbols file, and it’s used in some more advanced debugging scenarios that are beyond the scope of this book.
Here’s a common “gotcha” you should be aware of: if you switch to the release configuration, then go back to do more development on your application, be sure you remember to switch back to the debug configuration. In our case, now that your application has been successfully built, you should do just that: switch back to the debug configuration in case you decide to do more development on this program.
Goodbye, Hello World
In this chapter, you were introduced to Xcode and Interface Builder, the dynamic duo of Cocoa software creation tools. You designed a full-fledged application without writing a single line of code. You learned how to add a text label to your application’s main window, changed the label attributes, changed your application’s menu, gave your application an icon, and you even saw how to build a distributable version of your application.
In this chapter, you got your first taste of the power of Cocoa by seeing what you can do without writing any code. In the next chapter, you’ll see how powerful things start to get when you actually do write some code.
Chapter 3
Lights, Camera… Actions! (and Outlets, Too)
It really is amazing all the stuff you get free with Cocoa, as you saw in the last chapter. But there was something very important missing in the last chapter’s application that most applications will need: the ability to interact with the user. When you were in Interface Builder, in the last chapter, you saw that there was a whole library filled with objects like text fields and buttons that you can use to assemble your interface, but those user interface objects are no good if we can’t tell when they’re used or change the data they contain. In this chapter, you’ll see how those objects can be used to let users interact with your application.
In this chapter, you’ll first learn a little about the way OS X is organized so that you’ll know where the functionality you’ll be using resides. Then you’ll learn about the Model-View-Controller design pattern, which was the guiding principle used by the architects of Cocoa, and which should also be your guiding principle when writing your own applications. After that, we’ll discuss actions and outlets, which allow your code to interact with the stuff you build in Interface Builder. Finally, you’ll dive in and build another Cocoa application, but this time you’ll build one that gets information from the user and then responds to it.
A WORD ABOUT LEOPARD AND OBJECTIVE-C 2.0
Mac OS X Leopard (10.5) introduced some very big changes into the world of the Cocoa developer. With the release of Leopard, we saw the first major upgrade to Objective-C ever. Objective-C 2.0 brings a whole bunch of new features that make your life easier, including:• Garbage Collection, which automatically handles memory management for you.
• Properties, which free you from having to write accessor and mutator methods.
• Dot Notation, which lets you use accessors and mutator methods similar to the way Java and C++ work.
• Fast Enumeration, which provides a way to iterate over collections of objects quickly and with fewer lines of code.
Using Objective-C 2.0 in a Cocoa application makes the application only work on Mac OS X Leopard (10.5), Mac OS X Snow Leopard (10.6), or later versions. At the time of writing, however,