Thursday, October 7, 2010

Hello World - Basic App Tutorial with a Label

Once you have Xcode installed, you are ready to start making iPhone applications! Get excited, you are about to make your very first iPhone app. It is so easy too!

Open Xcode, and click on File -> New Project











Next, select Application under iOS on the left panel if it is not already selected. As you can see, Xcode can be used to program applications for Macs as well.


Once you have selected iOS Application, you will see a variety of application templates to choose from. For now we will focus on the basic View-based Application.

Select View-based Application and make sure the Product selected says iPhone.

Click Choose...

Type in the name of the Application, I suggest HelloWorld. Choose a location and click Save.


A new screen appears and there is a lot going on here.




















You will see on the left hand side Groups & Files. In this section, expand all of the folders to reveal the files associated with this project. I will discuss what these files do in detail later, but as for now, lets get our basic app running.


















Double click on HelloWorldViewController.xib (or this will be 'YourProjectName'ViewController.xib if you named the Project something else). Interface Builder opens!


There are a lot of things going on in Interface Builder. Luckily, many of the functions are intuitive. Interface builder offers easy-to-use drag-and-drop features that make designing the layout of an app simple. In the Library window, which can be seen on the left side of the screen shot, scroll down to find a Label. Click and drag the Label over to the gray window titled View.

Good job, you have now created your first Label! Lets change the title by double clicking on the Label you just added to the View. Change it to Hello World.
Now go up to File -> Save to save the Label you have just added. A shortcut for this is pressing the Apple/Command key and the S key (+S). Now switch screens back to Xcode. A shortcut for this is Apple/Command key and tab (+tab).
Now click on Build and Run at the top center of the Xcode window. The iPhone simulator should now pop up.
Congratulations! You just created your first iPhone application. Pretty easy right? The beauty of Interface Builder and Xcode is how they work together to easily create common application functionality. In this beginner app we didn't even have to write any code! Sure it doesn't do much but we are off to a great start.

A side note to those with little or no programming experience: Hello World is usually the title of the first program any developer creates. This is generally a very basic program that usually does nothing but display the text "Hello World". Many programmers start with this because it shows the very basics of running a program in a given language, environment, or system. Also it is believed to be bad luck if your first program does not say Hello World. Programming is tricky enough as it is, so the last thing you want is bad luck holding you back. Good job on your first app, soon I will explain some more features so that you can make one that is actually useful.

2 comments:

  1. Very easy to follow. Great Job!

    ReplyDelete
  2. Thank you for this tutorial, but I don't have X code knowledge, it's too difficult for me, that's why I found a more convenient solution for me to build first iphone app - using an iPhone app builder http://seattleclouds.com. This service helped me to do easy, without any programming skills, several applications.

    ReplyDelete