Tuesday, 24 May 2011

A Very Simple Hello World iphone app

So here is the simplest program you can create for an iphone using xcode (the IDE) and objective c. The all time classic that is hello world!

Step 1 - Download Xcode:

Go to the apple dev centre, register and download the latest version of xcode.

Step 2 - Open Xcode:

Launch Xcode, found under /Developer/Applications/. You will presented with a window like the one below. Select Create a new Xcode project.

Image and video hosting by TinyPic

Step 3 - Create the project:

The next window will present options for the various different types of projects you can create. Select "View based application". You will be prompted for a location to save the project and a name, call it "HelloWorld". Anywhere is fine, but I don't recommend putting it under the /Developer/ folder as apple have tendency to wipe that folder when you upgrade xcode.
Image and video hosting by TinyPic

Step 4 - Select the Simulator:

You should now have your "solution" open, with all the appropriate files pre-setup for you to launch your application in the simulator. Notice the drop down in the top left of the IDE, this lets you determine how you launch your app - via the simulator or onto your phone. Make sure Simulator is selected.

Image and video hosting by TinyPic

Step 5 - Open Interface Builder:

Ok, now we will actually modify our code to show "Hello world". If you look in the solution explorer ( on the left) and navigate to the /Resources/ folder. Double click on MainWindow.xib (pronounced nib files). This will launch a program called "Interface Builder". It should open at least 3 windows:

  1.  Library - a list of all components you can use on your interface
  2. Controller Window - The view which we will we modify - it represents the screen.
  3. Attributes Inspector Window- Used to alter properties of items on your interface ( fonts etc)
Select the Library and scroll down the list of components and select Label. Drag it onto the controller window like below. 

Image and video hosting by TinyPic

Click on the label that you have just dragged onto the controller. Select The Attributes Inspector Window and change the text property to "Hello World". Save the File by pressing cmd + s.

Step 6 - Launch Your App:

If we navigate back into Xcode and select the "build and run" option in the middle of the IDE, it will now launch your app in the simulator. If you select the breakpoints button ( just to the left), it will put you in debug mode and you can debug just like good old visual studio.

Image and video hosting by TinyPic

Ta, da! Hope someone finds that useful.

No comments:

Post a Comment