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
- Open your favorite web browser and go to http://developer.apple.com/iphone/program.
- Scroll to the bottom of the page and click “Download the Free SDK”.
- Click “Create Apple ID”.
- Input your information and click “Create”.
- In the downloads section, click “iPhone SDK”.
Installing Xcode
- Double click the DMG and you will be presented with a window containing the Xcode installation package.
- Double click iPhone SDK.
- follow the installation instructions. The default
- 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:
- Double-click “Macintosh HD” on your desktop.
- Double-click “Developer”
- Double-click “Applications”
- 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.
- Click “File -> New Project”.
- Click the “View-Based Application” icon.
- Click “Choose”.
- Navigate to a location where you would like to store
- your iPhone projects. In the text box labeled “Save As:” type “HelloWorld”.
- 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.
- Expand the “Classes” group on the left side by clicking on the small triangle next to it.
- Click on “HelloWorldViewController.m”.
- 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.
- 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!
nice great work. keep up good work.....
ReplyDeleteGood work Rashid ... Great going !
ReplyDeleteVery informative article for beginners ...
Thnx Waqas and Adnan. also wish you to join me in this effort.
ReplyDeleteThe reason why I have joined this blog is to learn from here:)
ReplyDeleteAnd brother, do let me know if I can play a part in continuing your effort!