XCode Tutorial Practice 1: Hello World iPhone App

Updated Oct 3 2013: This tutorial is compatible with XCode 5 AND XCode 4!

We’re taking a practical approach to learning iOS programming. This means lots of hands on work and practice!
In order to benefit the most from these lessons, you should open XCode and try to follow along.

This is part 4 of the lesson plan. Click here for the entire Learning Plan.

It’s time to change our blank XCode project so that we can see something on the screen of that iPhone simulator!

We’re going to be modifying the view through Interface Builder so click on ViewController.xib which is the default view that XCode has created for you. It’s also the view that your ViewController class manages.

When you select it, the editor area of XCode is going to change into a visual designer.

Before we proceed any further. Take a moment to look at this visual diagram of what the different areas of XCode are called because we’re going to refer to them by name.
(If you’d like a more in-depth tour of XCode right now, you can do so in my XCode guide)

xcode 5 tutorial: XCode 5 workspace diagram

If you’re using XCode 4, it may look a little different but the areas and tools shown in the diagram above are the same.

In the Library Pane which is the bottom half of the Utility Area in the lower right corner (you may have to click on ViewController.xib before you see the library pane), type in “UILabel”. If you don’t see UILabel, you may need to switch to the “Objects” tab of the Library Pane (The “objects” tab can be shown by clicking the blue cube icon near the middle of the Utility Area in the screenshot above).

Once UILabel shows up as a draggable control, you can click and drag and drop it onto your view.

Adding a UILabel to View

This will create a UILabel on your view.

At this point it doesn’t have any text, so on the right hand side property inspector, find the text property and type in “Hello World”!

Changing text on a UILabel

After you’ve modified the text, click the Run button on the upper left corner of the XCode interface and watch your Hello World app come to life!

Hello World App in iPhone Simulator

In this tutorial you learned how to add elements to your view from Interface Builder as well as how to customize properties on your UI Elements.

Frequently Asked Questions

If you have any questions on this tutorial, please ask in the comment section below and I’ll update this section with Q&A.

74 thoughts on “XCode Tutorial Practice 1: Hello World iPhone App”

  1. Hi Chris, I am able to click and drag the Label however, nothing appears on my screen. I do not get the blue dotted lines. Help please 🙂

  2. Chris. Thanks so much for putting these videos together. It’s fun to try and learn a new skill. I’m using 5, and when I first ran the program my “Hello World” was all the way to the right. I read through the comments and noticed that someone recommended unpicking the box in the inspector that auto formatted the project (in my mainstoryboard it was initially a big square instead of a “iPhone shaped” rectangle). I did that, and now my text is just off center to the left. Any ideas? Thanks!

      • Hey Chris, that’s the weird thing. It’s dead center until it renders. The same thing happened with each object in the next exercise (changing text with the text box and button)

        • Sounds like auto layout shenanigans! I’ve yet to write a tutorial on the subject, but this is a good one: http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

          If you just want to turn it off, in your storyboard, select your view controller and in the right pane (inspector) one of the tabs has an autolayout checkbox option you can uncheck.

          Basically the autolayout system works by specifying relative positions. For example, “position this label 100px from the left”. So what you see in the storyboard may not be reflective of how it’s really positioned. Each of these rules is called a constraint. When you run it, the label will be positioned based on the constraints.

          So you probably have accidentally specified some constraints for the label that you didn’t mean to. If you select your label, on the left side of the storyboard, there’s a list of constraints for the element.

  3. I have written codes in VB and I find this (for now) have a lot of similarities. I am using Maverick so obviously this tutorial (THANK YOU VERY MUCH) was written before the release of Maverick. Anyways, I have XCode and don’t see the ViewController.xib but instead, I see LaunchScreen.xib. I launch that and it isn’t similar to what is in the tutorial. Also, the uilabel if I search from the tools pane return empty. What am I doing wrong. Thanks!

  4. I dropped the the label in the middle. In fact, i actually centered it using the helper lines, but when i run the ios simulator the label is way off to the right side of the screen, only half-visible. Any ideas why?

    • Hi Peter, select your Main.Storyboard then go to the Utilities pane and select “Show the file inspector” and uncheck the box that say “Use Auto Layout”

      • oh man, you’re a life saver…. or at least a hair saver. i was pulling all of my hair out trying to figure out how to fix that. it seems so trivial. i didn’t want to move on until i figured it out. thanks!

  5. Hey Chris, thank you SO much for putting together these videos. Ive been searching for a long time how to learn Xcode but your website was the only one I understood.

    Thanks for everything….

  6. Hello Chris
    My label appears exactly in the center of the storyboard but when i run it it doesn’t appear in the center in the simulator. How do we fix that ? I am using Xcode 6. Do you teach such positioning and auto layout in your membership classes ?

  7. Hey Chris, I am taking your course. But when I try the lesson three (label) the screen comes up just plain white. Can you help with this?

  8. Is it normal if just appears the “iOs simulator” white screen, but not the actual “iphone”? Also I havent got the .xib file, just the storyboard, .h and .m. Thanks!

    • Hey Adry, you can just treat the storyboard as the XIB for this demo! If you click CMD+1, CMD+2 or CMD+3, you can change the zoom level of your simulator to display the bezel!

      • Awesome. Now I hope to review each concept and understand the keywords and labels functions. Thanks for the viddies and lessons!

  9. Hey Chris, (love your videos)When I try to run the app after adding the label, the build fails and comes up with three issues, I have no idea what any of it means, please help! I haven’t been able to successfully build any app without having an issue yet, and I have no idea what any of it means or how to fix it! Some help would be great!

  10. Hi Chris I am trying to follow your videos they are excellent but I am doing something wrong. I cannot see the .xib fil (2:04 on the video). I been trying to follow step by step but Is not showing me this file. I guess is here were you are able to see the visual interface and add buttons etc.. Please advise. I am using Verion 5.1.1 thanks Marcos

  11. I love your tutorials, I just wish I could follow along but my viewer and some other things don’t match up with what you say they should look like.

    • Hey Undergroundman, truly apologize for that! The course videos are updated but I’m still in the process of updating these free ones. The text version below the video is updated for Xcode 5 though so I hope you can follow that!

  12. Hello chriss,
    I am one of your newly joined student all the way from Dubai – UAE. I have recently shifted from PC to Mac and I love Apple products. I wish to become an App developer for Apple and this is what brought me here… I’ve been following your videos with close attention.Thanks for taking time and efforts to make videos and tutorials for the sake of making us understand Xcode Objective C… you’re the man! Bless you for this good noble cause you’re doing out here for all of us wanting to learn Xcode!

    • That’s for reading Salman. I agree that there’s just something appealing about macs. (could be just a psychological effect from there marketing/branding lol) Anyways, i hope you continue to read and watch and grow in your learning!

  13. Hello Chris!

    I Just stopped the video for a sec to write this comment. You must be by far the best online teacher that i ever came across. Thank you for putting these awesome tutorials online. I hope i will get to my first app, if i do so i will let you know!

    Thank you

    Toon-Bert

  14. I have xcode 5 and my ios simulator doesnt start with a blank screen but it already has apps on it like safari. Also when i double click main.storyboard it opens up a new window so i cant drag the label onto it because its in a different window.

    • Okay, so first off, When you open the ios simulator using main.storyboard, don’t double click it, single click. It should open not in a new window, but in the xcode window. Same thing happened to me, it had safari and other default factory apps. use the mouse and click and drag as if it were our finger and you will see your new app on the second page. Hope i helped!! Good luck!!

      • I found the label. It turns out I had to click on something on the lower right to be able to see the label. I am really enjoying your lessons and am hoping to be able to write an app for the iphone eventually. I have been a programmer/analysist for 30 years and am not used to having so many tools. I have always written all the code to execute, now all I have to do is pick and click. Of course the design can’t be done for you. Thanks again.

        • Hey Tony, you’re totally right about that! Especially with Xcode’s auto complete, sometimes i feel like i’m not even programming at all haha
          All i’m doing is typing a few letters and pressing enter and then repeating that over and over again.

          One note however is that you can completely avoid the storyboard and do everything programmatically. It’s preferred to avoid storyboards with larger programming teams because merging code is far easier compared to merging conflicts with XML (the storyboard file)

  15. Hey Chris. First off Thanks for these, you are awesome man.

    When I run it I get a dialogue box with: SpringBoard failed to launch application with error: -3
    Have you ever had that before? Any idea what to do to fix it?

    • Hey Ignasi, did you start an OSX application by accident instead?

      For the iOS projects, you can start with Empty Application, Tabbed Application or any of the other ones but they won’t really suit our purpose for this demo!

  16. Hi Chris,
    First, thanks for the awesome help! You have given me the motivation to do this.

    The problem: I cant see the ViewController.xib that you ask us to click on in this tutorial. Am i doing something wrong?

    Thanks!

    • Hey Sly, thanks for watching and I’m glad you reached out. I recorded the video with Xcode 4 but i added annotations for Xcode 5 to point out the differences.

      In any case, you probably see a Main.Storyboard right? Well just treat that as the same thing! You’ll be able to follow the tutorial.

      Please let me know if you have anymore questions!

        • Hey Frank, Storyboards are great for beginners to learn iOS programming with because you can lay out multiple views in a single storyboard. The xib file will only represent one view.

          There are a lot of debates over which one is better but each has its strengths and weaknesses. If you’re working by yourself, it’ll be based on personal preference, but if you’re working on a team, then everyone needs to agree on it. So if you know how to use both as well as create UI programmatically (after you learn more), you’ll be versatile.

          Anyways, back on topic.. Storyboards are easiest for beginners to learn with especially when you start working with multiple views. The xib file is just like storyboard except xib represents one view only. If your app is only 1 view, then there’s really not much difference.

          Thanks for commenting and reading!

    • Hey Amrendra, if you know another programming language already, then it may be possible to get familiar with Objective C if you spent a full 8 hours on it each day for a week going through demos and samples.

      But if you don’t have a programming background, it’s going to take a lot longer unfortunately. Most beginners start to become more comfortable with it after a month of dedicating an hour every day. If you’re a beginner, i would suggest going through the “Start Here” link at the top of this site.

      Thanks!

  17. one quick question chris, i need your suggestion. how many hours per day is the best practices to learning and practice to code from your videos.

  18. Right after the Xcode layout figure, you reference the “Library Pane”, which isn’t in the figure. I think a lot of people will be confused. You might want to point out the pane in the figure.

  19. I’m rapped with your videos. Problem: In my BlankDemo app I see no ViewController.zip file, only all the others, so I can’t get to the Interface Builder area. What’s wrong? How do I delete the project and start again, maybe I did something wrong on the way. Regards Sven

  20. Hi Chris,
    Thanks for the great step by step tutorials.
    My last go at programming was back in the 80’s using BASIC via the CLI.

    Things have changed a LOT since then. Figured it was about time to learn something new.

    Keep up the great work!

    • Hey Rachel, I’m assuming you mean Interface Builder rather than simulator that you’re trying to drag and drop the label into. That’s odd! What happens when you try? Are you able to drag the label around but unable to drop it into the grey area of your view?

    • Hey Rachel, based on the other comment, you’re using XCode 5 right? If so, then the reason you can’t drag the label onto the view may be because you’re in a “zoomed out” view. Try double clicking on an empty area beside the view to “zoom” back in. Then you should be able to drag it out. Give that a try and let me know what you see!

Leave a Comment

Share
Tweet
Pin