Hello World from the iPhone (part 2)
We continue our exploration of iPhone development. In part 1, we downloaded the latest version of Apple's development tools. In part 2, we'll create a simple iPhone application which displays the message "Hello World!".
Creating the Project
Let's start Xcode. We get the intro screen to xCode which looks like this:
Choose Create New Xcode Project:
On the left pane, you will have the choice of creating either iOS or Mac OS X applications or libraries (among other types of projects). Under the iOS selection, make sure the Application selection is chosen. For this project, we're going to choose a Window-based application. It will keep things very simple.
On the New Project screen, name the new project Hello World:
When the Hello World project has been created and the files saved, you'll be presented with the main Xcode window. In the left pane of the window, you'll see the Groups & Files which comprise the project. In the main pane of the window, you'll see a list of items which go into the building of the application. Take a minute and explore the items which comprise your project.
As a side note, I prefer the All-In-One view found under Xcode>Preferences. In later blog entries, I'll switch to this way of looking at things. Because I have a background using Visual Studio, I prefer one window to access project resources.
Building the Interface
Once we've created our project, we want to tell the World Hello! The development tools make this very easy to do. In the main project window, find the file named MainWindow.xib and double click on it. This will start the Interface Builder application. Interface Builder allows you to graphically design your application without having to wire up all the elements in your source code. For our Hello World project, Interface Builder would look like this:
Now select the Label item and move it to the window labeled Window. When you double click on the label item, you can change the text to "Hello World!". Let's do that and save the file and go back to Xcode.
Building the Project
We can now build the application by choosing Build and Run at the top of Xcode's main window (be sure the build target in the upper left hand corner of Xcode's main screen is set to Simulator). Xcode will automatically start up the iPhone simulator and launch your Hello World! application. Pretty easy: