Sunday, 5 May 2013

Your first iOS Application....!!

This is my first Blog post. This tutorial only introduces the tools, the fundamental design patterns, and the application development process.I hope it will be useful for others.
In this post i will try to explain how to start writing Objective-c code using Xcode IDE.

Before you start coding, you should have few tools (if don't have already) as listed below. 
  •  You should have a mac machine, with latest Mac OS X (10.7.x) installed.
  •  Download the latest Xcode IDE (integrated development environment), and install on your Mac.[Xcode download link:]
  •  Enjoy coding...!!

Let's start with a simple "HelloWorld" example.

Step 1:
Open Xcode, and select File->New->Project, see the image below.

Step 2:
Select "Single View Application". You can also select an "Empty Application" but in this case you have to add a controller manually to your project. So i suggest use  "Single View Application" it comes with a controller automatically. Press next.

Step 3: 
 Enter your project name, device type (in this example iPhone), and company identifier (Format   should be “com.anyName” ). Press next.

Step 4:
Set project location and press create button.

Step 5:
Your project will be created as shown below. You can see it's automatically creates
AppDelegate a ViewController and a UI (.xib) file, and some other standard folders
and files.

Step 6:
Now let’s start designing using .xib file. Select the “ViewController.xib”. Select a button object from the right side bottom corner window. Drag and drop the button object on the ViewController.

Step 7:
Now add a button title by double clicking on it. Here I am entering “Press Me”.

Step 8:
Now select “ViewController.m” file and add the below code in it.This method will be our button action. Inside this method we are creating an Alert which will display “hello World” message.

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Success !!!"
message:@"Hello World"
delegate:nil cancelButtonTitle:@"OK"
[alertView show];
[alertView release];

Step 9:
Now double click on the “ViewController.m” file, then it will open the file in a new window. Now select the “ViewController.xib” and right click on the button which you have just added (“PressMe” button). On right clicking it will display a black color window with lots of options. Search for the “Touch Up Inside” option. On the right side of this option you can see a radio kind of button, select that and link it to the “ViewController.m” file’s “onPressMeButtonClicked” method. This process will link the method to the button click event. Refer the below images.


Step 10:
Now it’s all done. Just select your simulator (I am selecting iPhone 6.0) from the top left corner and hit the “Run” icon to run the application.

Step 11:

It will take few min to open the iPhone simulator and your project. Your application will look like below image.

Step 12: 
Now click the PressMe button and it will display an Alert message.

So you are an iPhone developer now.
You can download the sample code here.