In teaching programming, it is traditional to begin with a ‘Hello World’ program to help get us familiar with the programming environment with which we will be working.
For this lesson I am going to use the iPad for the frame of reference in creating this application.
First, open Xcode and select Create a New Project.
On the next screen, select a View Based Application and change the Product to iPad (though this works exactly the same for the iPhone).
When you click on Choose, you will be asked to name your application. I named mine “HelloWorld”.
You have three (3) primary types of files when your Xcode opens: files that end in .h, .m, and .xib.
The .h files are Header files. They provide directions to the compiler (the thing that turns your code into a program) on what to expect. .m files hold the programming code for your project. .xib files (historically pronounced nib) hold the gui (graphical user interface) portion of your program.
In the IB
The IB (Interface Builder) is all we will need to work with for the project. Double click on “HelloWorldViewController.xib”. This will launch the IB.
On your initial launch you should have at least 2 windows open, the HelloWorldViewController.xib folder, which contains the File Owner, First Responder, and View, and the View itself (should be a blank rectangle that says View at the top). The View Attributes might also open, if it doesn’t it can be opened by clicking on the Tools Menu and then Attributes Inspector.
I’m going to save what each of these things does for a later lesson. For now, just open the Library (Tools -> Library) and scroll down the list of Objects until you find the Label.
Click and drag the label on to the View (the big rectangle). You can resize it with the controls (dots) around the label. If your View Attributes is open, you will be able to see information about the Label.
In the View Attributes, click in the Text area (where it says label), and type in “Hello World!”.
You can center, change the font, font size, etc all in side the View Attributes area. Once you have it looking the way you want, save and go back to the Xcode window. Click on Build and Run in the top center of the Xcode window.
If all goes as planned, you should see the simulator launch with your Hello World! displayed!
Below is a walk-through demonstration:
[tubepress video=qLAe3OmapQA]