Simple iPhone "Hello World" tutorial.
Monday, March 10th, 2008UPDATE: 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/
Here is a simple Hello World iPhone app that does nothing else but display "hello world".
1. In Xcode create a new "Cocoa Touch Application" Project called "HelloWorld"
2. Open HelloWorldAppDelegate.m in the Classes folder
3. Add this code to the bottom of the applicationDidFinishLaunching method:
[contentView addSubview:textView];
[textView setText:@"Hello World"];
[textView release];
The entire method should look like this:
// Create window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Set up content view
self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[window addSubview:contentView];
// Show window
[window makeKeyAndVisible];
UITextField *textView = [[UITextView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[contentView addSubview:textView];
[textView setText:@"Hello World"];
[textView release];
}
4. Click "Build and Go".
5. Hello World