iPhone SDK: Your First iPhone Application

Cocoa Touch | IOS | IPhone | Objective-C | Xcode

iPhone Application Development


This entry is part 6 of 9 in the series iPhone Application Development

As we learn all the required topics to cover base of iOS SDK. Now its time to start our first iPhone Application Development. Let’s create your first iPhone Application.

First iPhone Application

Step 1. Create new project in Xcode. From the template selection, select iPhone and then select Single View Application. This the most basic template and we will use this in most of the application.

iPhone Application

Step 2. Click on next. Then new screen appears, which allows you to specify your application name.

iPhone Application

For Project Name specify FirstApp or whatever you want. Do the same for company identifier. For Device Family we have iPod, iPhone or both. Just for now select iPhone. Uncheck the use storyboard option as well as include Unit Tests option. We will use them later as we progresses.

Click on Next.

Step 3. Clicking on next will ask you to specify location for your project. Specify location and uncheck the git directory option for your project. Click create. This will create project name group in xcode, which contains 5 different files. I name my project FirstApp so I get following 5 files:

  1. FirstAppAppDelegate.h
  2. FirstAppAppDelegate.m
  3. FirstAppViewController.h
  4. FirstAppViewController.m
  5. FirstAppViewController.xib

We will not touch first 2 files for now. Select FirstAppViewController.m file, which contains lots of prewritten code. Delete some methods so that your view controller’s implementation file will look like below:

iPhone Application

Click on FirstAppViewController.xib file. Xcode opens user interface for your iPhone Application.

iPhone Application

Step 4. Click on the third button from the view button group. Which is located at top right corner of Xcode window. This will bring a right sidebar in user interface.

iPhone Application

Next click on third icon in Interface Builder Document from right sidebar.

iPhone Application

This is just setting for proper environment to work on. Now without doing any change hit run and what you will see is iPhone Simulator, which is designed to test iPhone application in Xcode while developing.

iPhone Application


Our application is running in iPhone Simulator. There’s nothing in it except a grey screen cause we haven’t inserted any code or done any design yet. This is the basic single view template that we are working on. iPhone Simulator gives you exact same output that you will get when you run same application in iPhone Device still it offers some limited functionality like it’s not supporting camera obviously and some other too. But for our purpose it’s fine.

Step 5. Let’s add some objects on user interface. Open FirstAppViewController.xib, on right sidebar from object library drag label, which is first, object by default and drop on user interface design. As you move label over user interface it starts guide you to position. Out it in center (guides will help you for that).

iPhone Application

Now click on Run and see the result. Its similar to what we saw on User Interface. Pretty easy!

iPhone Application


Step 6. This is static content. But let set this content by code instead of in design. To do that first have to link label to our View Controller and it’s easy. Open FirstAppViewController.xib file and from top right corner click on second editor button and your environment will bring that interface file just beside the user interface. Now hold down control key, drag label and drop on interface block, which then opens a popup that look similar to the below one:

iPhone Application tutorial

Specify Name whatever you like and click on connect. Which will write following code in interface file:

Just remove that {} code (code highlighted above) cause we will do that in different way. Now open implementation file and code similar to below is also written. (see highlighted code)

update @synthesize as follows:

Remember we do that while declaring properties in class. Now update viewDidLoad method in implementation file as follow:

we can also write this line with using square brackets like this:

[[self displayLabel] setText:@”Code Riddles”];

viewDidLoad method invokes when our view(user interface) is loaded in memory. At that time we are updating the displayLabel’s Text Property, which is linked to the label we put in user interface. Now hit run and see the output.

iPhone Application tutorial
Series Navigation<< iPhone SDK: Using Existing Objective-C ClassesiOS: Working with Actions & Outlets >>

Bookmark Link using: bookmark at folkd