Iphone hello world example
In this tutorial an iphone based hello world example is demonstrated. Also some relevant information under based is provided which we will find useful while dealing with large and complex iphone or mac os applications. So lets start building your iphone first hello world example.
Before starting you should have xcode, an integrated development environment and xcode sdk as provided by apple.
Now here i am convincing myself that you have mac os platform in which you have successfully installed xcode ide and sdk. So open xcode, create a new project switch to view based application and name it as Hello World and save it. Here i have save my project on desktop.
After doing the above jobs, xcode will open a project window. We are going to spend our most of the development time on this window only. Our project window is divided into three main panes or section. We have our Groups and Files pane in the left side of the window. This window section contains all the resources that make up our project. The top right pane of window is the Detail View which shows the detailed information about items selected in the Groups & Files pane. Now we have a lower right pane called Editor pane. Any file you select inside Groups & Files pane will be opened on the Editor pane by xcode. On this pane we write and edit our application' s source code.
Now lets know about the files listed under Groups & Files section. Inside the section we have five subfolders: Classes, Other Sources, Resources, Frameworks, and Products. Lets get them on by one.
Classes :- All Objective-C classes belongs to this folder. For the better organization of the code, we can create subfolders under the Classes folder.
Sources Other :- This folder contains source code files which aren't Objective-C classes. In beginning there are only two files present in this folder and they are Hello World_Prefix.pch and main.m respectively.
Hello World_Prefix.pch :- Extension .pch stands for "precompiled header." This file contains a list of headers that belongs to external frameworks and are used inside our project. Whenever the project is compiled or executed our application xcode precompiles the headers contained in this file, which ultimately reduces the building time of the application.
main.m :- This is our main file where our application's main () method is present. This file usually remains unedited.
Resources :- This folder contains files like icons, movies, images, texts and sounds. This folder contains three important items which have there independent importance while developing application inside the project. These files are Hello_WorldViewController.xib, Info.plist and MainWindow.xib.
Hello_WorldViewController.xib :- Information used by the program Interface Builder is contained in this file.
Info.plist :- Information regarding our application is stored in this property list file.
MainWindow.xib :- This is the main nib file in every application. Usually this file remains untouched but in large complex application it is altered.
Frameworks :- This folder contains libraries which contains codes and resources for example images and sound files.
Products:- This folder contains the output of the project Hello World.app file which the project creates. This file is installed on your iphone mobile hardware. Initially your this .app file is in red color, this is because it has not been compiled yet and when you compile your project the red color vanishes.
Since we have covered most topics required for building an iphone application, therefore now we are continuing with our hello world project. So till now we have created a view based application project with name Hello World and i have saved it on my desktop. Ok in the project we will be creating a label and going to write text Hello World inside the label. Here i will do this with the help of the program Interface builder but it can also be done programmatically.
As per my opinion using interface builder is till now more plausible. So from the Groups & Pane section open Resources folder and open Hello_WorldViewController.xib file. This will open the file inside the interface builder program. In the Hello_WorldViewController.xib window open the view window. Now click on tools->attributes inspector. From there change the background color of the view. Now click on tools -> Library. From here drag drop a UI Label view on the view window, then adjust the size of the label then from the Label attributes section and write the text Hello World and press enter, this wiil make the text visible inside the label.
After this press mac key + s to save the changes done in to file Hello_WorldViewController.xib and then close the interface and return to your project window and press mac key + r or click on build and go for compiling and running the program. If the project is compiled successfully then a .app file is generated and installed in to the iphone simulator. And after this your iphone hello world application is executed inside the iphone simulator.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.