Introduction:
I am going to show you the simplest way to create hello world iPhone tutorial. I will write few more tutorials on the basic of iPhone Development. So this tutorial is an absolute beginner guide for iphone development. To get start with iPhone development you need to have iPhone SDK which you can get from here (http://developer.apple.com/iphone). To download it you need to have a apple developer account which is free for everyone. To test the code on device (iPhone) you need to buy a developer license which cost you 99$ or 299$ for enterprise.
Getting Started with iPhone Development:
To start with hello world iPhone tutorial, you should read the “getting started with iPhone” tutorial which covers the things you need to know before starting development for iPhone( You can also watch the video tutorial of “Getting Started with iPhone” ). I also write a tutorial for businessman and designer to know about the iPhone development cycle (“iPhone Development Guide” ). So if you are a beginner for iPhone, you should read my tutorial before starting iPhone development.
Idea of this tutorial:
There are already many tutorials on hello world in iPhone but I want to write a very basic tutorial on iPhone sdk which will cover xcode, iphone project files and interface builder. This is a basic hello world tutorial which will be extended to a big project later on. So before reading other tutorials on my blog I highly recommended you to read this beginner’s Guide to iPhone development. OR you can watch the video tutorial here if you have no time to follow easy steps
.
Final output of hello world tutorial
Simple Steps to create hello world iPhone application
Step 1:If you have read the getting started tutorial, then you have a xcode installed on your mac machine. Open the Xcode and click on File > New Project. Select “View-Based Application” and click on “Choose..” button. Name this project “Hello World” and click “Save” button. Now you have a template for your hello world iphone project.
![First iPhone application Picture 26 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 26.png)
Create a new Xcode Project for iPhone application
![Hello world iPhone Tutorial Picture 1 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 1.png)
Select the basic design for your first iPhone application
![Simple iPhone SDK Hello World Tutorial Picture 2 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 2.png)
Name your first iPhone applcation
![Getting started developing on the IPhone SDK Picture 3 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 3.png)
Xcode project template created
Step 2:Now click on Build and Go button to run this template application. It will start the iPhone simulator and you can see a gray screen on that. Click on Home button and it will show you a HelloWorld icon on the dash board of iPhone simulator. If you click on it again, it will open the application again. iPhone simulator is best tool to test your application before you deploy it on your device for testing or even before submitting to apple store.
![Beginner iPhone SDK Hello World Tutorial [Example & Code] Picture 5 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 5.png)
Build your First iPhone application
![Output of your first iPhone application Picture 6 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 6.png)
Output of your first iPhone application
![Beginner iPhone SDK Hello World Tutorial [Example & Code] Picture 27 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 27.png)
Press this button to quit your first iPhone application
Step 3:Now open Xcode project and select HelloWorldViewController.h file and type the following code inside interface:
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
Also write this method before end of this class
- (IBAction) submitYourName;
Step 4:So your HelloWorldViewController.h file will look like this:
#import <UIKit/UIKit.h>
@interface HelloWorldViewController : UIViewController {
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
}
- (IBAction) submitYourName;
@end
Step 5:Now open HelloWorldViewController.m file and type this method before @end - (IBAction) submitYourName;{ lblUserTypedName.text = txtUserName.text; }
Step 6:Now lets start some design on interface builder. For that open your xcode project and in “Group & Files” looked at bottom, you will see “NIB Files”, expand it and you will see two design files for your classes. One is the MainWindow.xib which is the main window or entry point to your application. Other one is HelloWorldViewController.xib file which is mapped to your controller class “HelloWorldViewController.h. For now I just want to change in HelloWorldViewController.xib file. Double click on that file to open it inside interface builder.
Step 7:Click on Tools and select Libaray (cmd + shift + L) and drag the text field to your view. As text field is already selected, click on Tools>Inspector (cmd + 1) and in Text field type “Your Name”.
Step 8:Now drag the TextField from Library to your view (cmd+shift+L) and also drag another Label inside view. Make sure label is selected, Click on tools and select “Size Inspector” (cmd + 3) and change the width of this text field to 250. Also go to tools and select Inspector, change the layout to center.
![Add Text field to your first iPhone application Picture 11 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 11.png)
Add Text field to your first iPhone application
![Add label to your First iPhone application Picture 12 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 12.png)
Add another label to your First iPhone application
![Change Label Width Picture 17 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 17.png)
Change Label Width
![Center UILabel from Interface Builder Picture 18 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 18.png)
Center UILabel from Interface Builder
Step 9:Last thing is to drag a button to the view (19) and then open Inspector again by selecting tools>Inspector. In Title type “Submit”.
Step 10:Now map the controller class variable function and methods with interface builder. Select File’s Owner in Interface builder and select connection inspector from Tools cmd + 2
Step 11:Now you can see that two new variables are added in connection inspector txtUserName and lblUserTypedName. Click on txtUserName radio button and drag it to text field in view (as you can see in the image)
Step 12:Do the same with lblUserTypedName, select its radio and drag it to below label.
Step 13:Now the last step is, click on submitYourName radio and drag it to the button and select touch down from the list.
Step 14:Now close the interface and open xcode. Either press cmd + r or cmd + enter or simply press of “build and go” button to run this hello world application. It will open the simulator in iPhone.
Final output
iPhone hello world tutorial code
You can grab this code from here.
Now watch me doing it
Click on this link to view the video screen cast for hello world iPhone application tutorial.
![Hello world iPhone Tutorial Picture 25 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 25.png)
![Structure of your iPhone application Picture 28 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 28.png)
![Interface builder Look Picture 8 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 8.png)
![Add label to your First iPhone application Picture 9 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 9.png)
![Change text in your UILable Picture 10 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 10.png)
![Add button to your First iPhone Application Picture 19 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 19.png)
![Change Text in your UIButton Picture 20 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 20.png)
![Map your controller with Interface Builder Picture 13 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 13.png)
![Map your text field with Interface builder Picture 14 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 14.png)
![Map your Label field with Interface builder Picture 15 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 15.png)
![Map your button with Interface builder Picture 21 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 21.png)
![Set action type of Button Picture 23 Beginner iPhone SDK Hello World Tutorial [Example & Code]](http://adeem.me/blog/wp-content/uploads/2009/iPhoneDevelopment/HelloWorldiPhone/Picture 23.png)



Thanks for very nice tutorial! This was very helpful for me.
BTW, I found a few miner errors:
Step 3 & 4
lblUserTypeName -> lblUserTypedName
Step 5
Do we need semicolon after submitYourName?
Step 6
“NIIB Files” -> “NIB Files”
Step 7
text field -> label
Thax Toru for correcting me
About step 5, there is no difference if you put semicolon after the function. But still thanks lot
Thanks for this great tutorial. I’m starting.
I do not understand this line of text, “Now map the controller class variable function and methods with interface builder.” I would be happy if someone explained it to me
Interface builder is really a handy tool. Once you write the code on your controller and want to link UILabel and UITextField or UIButton to your views which you made. You have to link them. So link would be a better word to use here (sorry).
What I want you to do is, after writing the code you want some connection between code and your views (which you design in interface builder). So you select the controller (File’s Owner) and then press cmd + 2 to open Inspector. Now in that place you can see all your class variables or methods which you declare as IBOutlet or IBAction in your .h (header) file.
So what I want here from your side is, select File’s Owner and then open inspector. Then you will have to link those class variables to interface builder design. You can see the Images or Video I attached with this post. If you still have questions regarding iPhone. Please feel free to contact me.
Thanks for you share now:)really usefull tips
Thanks for this, i just made my first iPhone app!
Thanks for these tutorials. Please, include a script in each tutorial that uses it that makes the keyboard go away. The tut is not finished until the keyboard is gone.
Thanks!
@Steve,
I am adding a tutorial 2 tomw and you can check it how to hide the Keyboard in that
Hi Adeem,
Thanks for the tutorial. I’m just starting and followed the tutorial, but got stuck at “map the controller class variable function and methods “.
I selected the “File’s Owner” and then opened the connections inspector, but I don’t see the variables there which I could map.
Could you please help.
@Abhi
…
send me your code at info @ adeem.me and I will check what you are doing wrong
Hi everyone,
I think must people are getting trouble mapping the controller class variables and functions on interface builder because they didn’t build the application before to go into the interface builder.
It could be solved by adding “Build the application with cmd + B” at the end of the step 5.
Hope this helps.
Thanks,
Hello,
I am just starting so spare with me and thank you very much for the tutorial. I finally was able to make the connections between the variables and the user interface. However, when I run the simulator the screen exits the controller view. So I click again on the app, it acts as if is trying to open the controller view but it doesn’t it just exits again. Any idea of what’s going on there?
I think you can use eclipse with aptana plugin to do iPhone app development in windows. Isn’t it true?
Great Tutorial – Will keep doing more…
this does not work the code messes up says 8 errors 1 warning why????
Excellent tutorial especially for a beginner like myself! Thanks.
Hi, I just downloaded and on Snow Leopard. There don’t seem to be a View-Base Application to choose.
I see only Cocoa Application, Cocoa-AppleScript,Quartz Composer and Command Line Tool. Thanks.
A helloWorld tutorial should be aimed at complete noobs, yet steps 3 and 4 have no explanation of what the hell you are doing
I presume they are creating instances of the text field and label, but me being a noob assumed that this would be done using the IB somehow?
Stupid tutorial man, you need to explain what your getting the noob to do otherwise they aint learning jack
Great tutorial for starters! I just made my first working iPhone app thanks to this tutorial!
I’m definitely going to check back here later for more tutorials:)
Keep up the good work!
BJ, I have the same problem, downloaded iPhone SDK, but Xcode does not show the View-based icon. Did you resolve the issue?
In fact, to add to my question, the iPhone section in Xcode is missing. Only the Mac OS X section is there. I have installed the iPhone SDK 3.1.3 for Leopard (I have version 10.6.2) with Xcode updates from developer.apple.com/iphone ….
Solved. Apparently my existing Xcode was not updated, but a new Xcode (with iPhone development stuff) was installed in another location. That one has both iPhone and Mac development.
Hi,
I get this error when compiling and can’t figure it out:
- (IBAction) submitYourName;
{
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@”SecondView” bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller setUserSelectedName:txtName.text];
error: ‘txtName’ undeclaired’ (first use in function)
I have tried everythig I can think of, can you shed some much needed light?
Thanks, David
// lblUserTypeName.text = txtUserName.text;
}
Hi,Guys, thank’s a lot for a lesson. One question: On the eleventh step in outlets window i can see only one outlet “view”, instead of your screenshots, where is a problem, can you help me please.
BR
Dmitry
@Dmitry
Can you see what is selected? Did you select the “Files owner” ?
Hi Adeem Basraa!
I did on the 5th step cmd-b and everythings fime right now!.
Thankl you for this lesson!
Best Wishes!
Hi very helpful tutorial for beginner like me , 1 Q how to dismiss the keyboard after type in the text box ? Thank you.
this is nice understandable way.
u please send dummy projects
I didn’t understand your last line.
Hi,
I have made a website in VB.net and now i want to make the Iphone application of that website & i also want to use that database which is used for VB.net Website.
Please guide me how can i make this type of application.Can i use the (Sqlserver2005) for IPhone application?If yes please guide me & if no that how can i make the IPhone application and i want to use that database which is used in my VB.net website.
Hi Adeem Basraa,
Really thanks for your tutorial.
Thank you so much!! I am an absolute noob and I have been reading and struggling with tutorials for the last day now and yours has been the easiest to use and understand, worked perfectly
thanks for the nice tutorial i was having confusion in dragging radios but really its so simple coz of your tut
hi
i just started iphone dev and this tutorial is very easy to understand
i rely appreciate it
thanks and regards
abhishek
Thank you bro,
great job. I followed this lesson also i watched the video but when I reached step 10th I don’t have like yours on Qutlets . I am using the last version of SDK. also I had Interface builder files= NIB Files .
waiting your reply
Great step by step, but the SDK won’t let me connect lblUserTypedName to the actual label. Any help?
Nice Code!!
I am able to create iphone Application in Half hour using this
Code !!
Thanks
Priti Parikh
great tutorial, thanks
VERY USEFUL TUTORIAL…..THANKS!!!
Hi
Thank you, it worked, I will now goto more advanced tutorials. But thank you for this one.