HelloWorld Example In Xcode 4 – iPhone OS 4.3


This is the “Hello World” example. I am going to execute the Hello World example in a new version of Xcode. So many things are new in this Xcode 4.

Xcode 4 is the complete toolset for building Mac OS X and iOS applications, the tools have been redesigned to be faster, easier to use, and more helpful than ever before. The Xcode IDE understands your project’s every detail, identifies mistakes in both syntax and logic, and will even fix your code for you. Quite simply, Xcode 4 will help you write better code.

So let see how it will be work.

Step 1: Open a Xcode, select Create a new Xcode project (See fig 1) and click open button.

Figure 1

Now select ViewBase application and click next (See figure 2)

Figure 2

Next page you need to define Product name and Identifier name, the identifier is the name of your application. It’s the same name used when you register your application at Apple’s website and release it to the AppStore. The Product name “HelloWorld Xcode4” and the Identifier name “com.mycompany.APPLICATIONNAME” (See figure 3). Select the Device Family into iPhone. Now select next and save the application in your disk.

Figure 3

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory (See the figure 4).

Figure 4

Step 3: Expand classes and notice Interface Builder created the HelloWorld_Xcode4ViewController class for you and generated a separate nib, HelloWorld_Xcode4ViewController.xib, for the “HelloWorld_Xcode4”.

Step 4: Select the HelloWorld_Xcode4ViewController.h file from the Project Navigator. We have added UILabel for display the text and added IBAction buttonPressed; in the file, so make the following changes in the file.

Step 5: Double click the HelloWorld_Xcode4ViewController.xib file from Project Navigator. Now the .xib window will look like (figure 5).

Figure 5

a) Now drag the label and RoundRect button from the object (See figure 6).

Figure 6

b) Select Label from the Window and change the label Text name from the Attribute Inspector (See figure 7). Give the Text name “Hello World!!!”.

Figure 7

c) Next select the RoundRect Button from the window and select Attribute Inspector (See figure 8). Give the Title “Click Me”.

Figure 8

d) Now connect File’s Owner icon to the “Hello World!!!” label and select label (See figure 9).

Figure 9

e) Select “Click Me” button and bring up Connection Inspector (See figure 10) and connect Touch up Inside to the File’s Owner icon and select buttonPressed: method.

Figure 10

f) Select File’s Owner icon to the View window and select view (See figure 11).

Figure 11

Now save it and open the HelloWorld_Xcode4ViewController.m file from the Project Navigator.

Step 6: In the HelloWorld_Xcode4ViewController.m file make the following changes.



Step 7: Now Compile and Run the application and see the Output in the Simulator.

You can download source code from here HelloWorld_Xcode4

Comments 16

  1. Thank You for the article. I got through it and it helped me. 4 out of 5.

    As a beginner, I found the wiring instructions to be a bit confusing and had to fidget around quite a bit. Step 5(d) w/ figure 9 had me confused and 5(e) helped me experiment and sort things out. I’m not sure if 5(f) is required at all. That wiring is already present and if it wasn’t then I certainly wouldn’t know how to do it based on the image or the instruction.

  2. As a beginner I found this didn’t work at all. Interface examples do not match the version of XCode I have: 4.0.2 and it just gets utterly confusing as the examples and images simply do not bear any resemblance to the multiple windows I have when opening files. I’d give it 1 out of 5

    • This example is build on Xcode 4 and iPhone OS 4.3 and you are using 4.0.2 Xcode version. thats why you facing problem.

  3. Very helpful article. Thank you. I had a little difficulty with steps 7 d,e, and f, but on the whole it was very simple to follow.

  4. I found this example to be very helpful. I did have a little problem with the connections as it is not clear how to make them but once you do it answers a lot of questions. Thanks for creating this example.

  5. I also had a problem with the connections on step 5d and 5e. I just got lucky. More detail is required there.

    By the way for brand new users more detail is required about displaying the property panels using the selectors on the right hand side. The latest (current) version of xcode 4 does not display these panels by default. Also it does not display the main ui view by default, you have to select it.

    This is a great intro and a good framework to begin an understanding of the very basics of iPhone application development. I am very grateful to get this start. Thank you!!

  6. I am still trying to figure out Steps 5(d). I am able to get the debugger to stop in the clicked event but the label text doesn’t actually change. I’m guess this is because I have not connected to label in the view to the “@label” property in the code. I am pretty sure this is related to step 5(d) but I do not know how to resolve it. :(

  7. Hi, followed this through.

    But what I don’t undertsnad is when you say make chnages to the .h and .m files what XCode has prepopulated bears no relationship to what you have and I’m having to type most of it in.

    When coding I can live with that but for the most basic of GUI tests it’s ridiculous and as novices how are we menat to know what to type in.


  8. Hi-Complete newb here…..I am struggling through the Xcode intro and i keep hitting the same problem, on:

    self.label.text = greeting; I get:

    ‘property ‘text’ not found on object of type ‘UIButton.’

    Can you help please?

  9. Hi-Complete newb here…..I am struggling through the Xcode intro and i keep hitting the same problem, on:

    self.label.text = greeting; I get:

    \’property \’text\’ not found on object of type \’UIButton.\’

    Can you help please?

  10. I’m sorry. your screenshots look nothing like my xcode downloaded last week. Even the file names are different. I am lost and flummoxed. For very new beginners, could you please publish an update?

Leave a Reply

Your email address will not be published. Required fields are marked *