Writing Your First iPhone Program

The Apple iPhone is becoming a full-fledged development platform. It's reliance on desktop- class operating system software is allowing it to become the most powerful mobile platform available. Here is how you can get in on the action, even if you have never written a line of code before! First, you need an Apple computer with an Intel processor and Mac OS X Leopard. I'm sure that Apple would be happy to help you with this step. We're going to jump right into making a program, but first we need to define a few terms.

Software Development Tools
Apple's IDE is called Xcode, and is available for free on Apple's software development website to anyone who registers as a developer. Apple has repackaged Xcode with iPhone development resources and called it the iPhone SDK.

Registering as a Developer and Downloading Xcode
  1. Open your favorite web browser and go to http://developer.apple.com/iphone/program.
  2. Scroll to the bottom of the page and click “Download the Free SDK”.
  3. Click “Create Apple ID”.
  4. Input your information and click “Create”.
  5. In the downloads section, click “iPhone SDK”.

Installing Xcode
  1. Double click the DMG and you will be presented with a window containing the Xcode installation package.
  2. Double click iPhone SDK.
  3. follow the installation instructions. The default
  4. selections for each screen are fine.

Running Xcode
Because Xcode depends on many system-level services and includes many programs, it does not install into the Applications folder. To run Xcode and other tools thatcome with the iPhone SDK:
  1. Double-click “Macintosh HD” on your desktop.
  2. Double-click “Developer”
  3. Double-click “Applications”
  4. Double-click “Xcode”


Creating Your First Project
Xcode's user interface, like most Mac applications, is composed of many windows that are tied together with the main menu at the top of the screen. The first time Xcode is run, it will present a welcome screen. These screens can be helpful, but not at the moment. Close them and we will create your first iPhone project.
  1. Click “File -> New Project”.
  2. Click the “View-Based Application” icon.
  3. Click “Choose”.
  4. Navigate to a location where you would like to store
  5. your iPhone projects. In the text box labeled “Save As:” type “HelloWorld”.
  6. Click “Save”.




Writing and Compiling Your Program
The window you are seeing now is the main IDE program. It has the editor and controls for the compiler built into it. We will now add the code to create a button and a button action.
  1. Expand the “Classes” group on the left side by clicking on the small triangle next to it.
  2. Click on “HelloWorldViewController.m”.
  3. Scroll down to the second green code region. This is a code comment showing where to put your code if you are creating your user interface using code.
  4. Put the following Code in ViewDidLoad Method


Add This code to viewDidLoad method

- (void)viewDidLoad {
[super viewDidLoad];
UIButton* helloButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
helloButton.bounds = CGRectMake(0.0f, 0.0f, 200.0f, 50.0f);
helloButton.center = self.view.center;
helloButton.font = [UIFont boldSystemFontOfSize:30.0f];
[helloButton setTitle:@"Hello" forState:UIControlStateNormal];[helloButton addTarget:self action:@selector(helloButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:helloButton];
}

Add this Method to the file also

- (void) helloButtonPressed:(id)sender {
}
[(UIButton*)sender setTitle:@"Hello World!" forState:UIControlStateNormal];
}

Now Your Files Looks As

Running Your Program
Now we have some code written for the compiler to compile and the simulator to run. To compile your code and start the simulator running your program, press the “Build and Go” button at the top. If asked to save your changes, press “Save All”. The simulator will start up and run your program. Congratulations on writing your first iPhone program!



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

4 comments:

  1. nice great work. keep up good work.....

    ReplyDelete
  2. Good work Rashid ... Great going !
    Very informative article for beginners ...

    ReplyDelete
  3. Thnx Waqas and Adnan. also wish you to join me in this effort.

    ReplyDelete
  4. The reason why I have joined this blog is to learn from here:)
    And brother, do let me know if I can play a part in continuing your effort!

    ReplyDelete