iPhone Development 101

iPhone 101

Code Tips

Resources

More

This tutorial was written for Xcode 3.2; it's outdated now. For a more up-to-date tutorial, check out Apple's App Development Tutorial to learn how to write iOS apps. There are also lots of other excellent books and online tutorials you can learn from.

If you'd like to find out when the updated version of this class is ready, follow me on twitter:

You'll be using two programs to build your iPhone apps: Xcode and Interface Builder. Interface Builder is where you'll build the User Interface (UI); we'll look at that next. Xcode is where you'll write the code that makes your app work.

Preferences

The first time you launch Xcode, you may want to set a few preferences to make coding a bit easier. Look under the Xcode menu and select Preferences ( ⌘, ). The Xcode Preferences window has a side-scrolling list of icons for different preference sets. Right now you're only interested in these two:

Code Sense - set "Automatically Suggest" to immediate. This enables code completion: as you type in your code, suggested code completions will pop up in light blue. You can hit the tab key to use the suggested completion, or keep typing to ignore it.

Building - set the Build Results Window to "Always" open during builds:

Debugging - make sure that "On Start" says "Show Console". You'll be using the console a lot to view log output - and to view crash info when your app crashes. Check the "Auto Clear Debug Console" checkbox also.


Creating a Project

An Xcode Project is where all of your app's data, images, and code are stored. To create a new project, go to the File menu in Xcode and choose New Project.

On the left side of the New Project window you'll see sections for iOS and Mac OS X. Click on 'Application' under iOS. There are several different iOS application templates available:

Different templates have different sets of Nib (UI) files and code already set up for you, but the most basic type is the "Window-Based Application". You can start with a Window-Based Application and create any kind of app.

Go ahead and create a new Window-based application and name it "First". We'll be using this project to explore Xcode and to create your first iPhone app.

The Project Window

When you create a new project, you'll start off in the project window. There are several parts to the project window:

The Groups & Files frame on the left is the organizer for all of the files in your project. You can organize things any way you like; typically your class files (the .h and .m files) will go in the Classes folder, and images, Nibs, sound files and other assets go in the Resources folder.

Open the Classes folder to see what's there now. Since you selected a Window-Based application, you'll start off with two files: FirstAppDelegate.h (the header file) and FirstAppDelegate.m (the implementation file). These two files (header and implementation) make up a class in Objective-C.

Additional References

TopHome