iPhone Hello World (In 3 lines)

February 6th, 2009

I’m a big fan of simple, short tutorials that do what you need quickly. Here is a simple iPhone hello world tutorial with 3 steps and 3 lines of code. Download the source code

  1. Create a new iPhone project of the “View-Based Application” type. ( Helper Image )
  2. Open HelloWorldViewController.m in the “Classes” folder, uncomment the ViewDidLoad method on line #35 and add this code to it:( Helper Image )

    1
    2
    3
    4
    5
    6
    
     - (void)viewDidLoad {
        [super viewDidLoad];
    	UILabel *helloLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 30, 100, 30)];
    	[self.view addSubview:helloLabel];
    	helloLabel.text = @"Hello World";
    }
  3. Hit the “Build and Go” button and watch the magic.(or select Buld->Build and Go)

5 Responses to “iPhone Hello World (In 3 lines)”

  1. Aaron Spjut » Blog Archive » Simple iPhone “Hello World” tutorial. Said:

    [...] UPDATE: This tutorial no longer works with the latest iPhone sdk. I recommend this tutorial instead: http://icodeblog.com/2008/07/26/iphone-programming-tutorial-hello-world/ [...]

  2. ASin Said:

    Nice Thanks! Works for me…. using iphone 3.0 sim

  3. Tom Said:

    Thanks! That’s exactly what a hello, world should be. Simplest program, so complete beginners can get started.

    Took me longer to google the tutorial than to get it working.

    Great!

  4. Chris Said:

    Doesn’t get any easier than this. Thanks!

  5. ram Said:

    excellent jump start thanku!

Leave a Reply