Developing for iPhone

Learn how to create and develop iPhone applications from scratch.

Tagged with ‘Objective-C’

I know you are probably itching to get stuck into the iPhone programming environment, but there are a few things you HAVE to learn first. One of them is Object Oriented Programming. The reason I am jumping right into this is that it is the main feature of Objective-C and a very powerful set of tools which you will need to understand if you want to create iPhone apps.

Let’s start by creating a new project in XCode. Fire up XCode and follow these steps:

  1. In XCode, click File > New Project
  2. Choose Command Line Utility > Foundation Tool
  3. Name the project “Objects Intro” and save it.

In the project window, click the Source folder in the left-hand pane to view your source files. You should have one called “Objects Intro.m” and one called “Objects Intro_Prefix.pch” (which you can ignore for now.)

Object oriented programming languages are based around the use of objects. Objects can represent real life objects (like a chair or a car), or can be more abstract. Objects can hold variables, change variables and pass information between each other. This makes the development of complex applications much more simple. You will understand them more as we continue. Let’s make an object right now!
 

Read the rest of this entry »

Tutorial 1-4: More Variables

Posted by Henry On April - 14 - 2009 1 COMMENT

In this tutorial, I will be showing you a couple more ways to use variables.

Open your “Hello World” project from the previous tutorials, and open the “Hello World.m” file to start editing. Edit the program so it looks like this:

#import <foundation /Foundation.h>
 
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
	int age;
	int fingers;
 
	age = 99;
	fingers = 10;
 
	NSLog(@"I am %i years old and I have %i fingers!", age, fingers);
 
    [pool drain];
    return 0;
}</foundation>

Read the rest of this entry »

Tutorial 1-3: Introduction to Variables

Posted by Henry On April - 13 - 2009 1 COMMENT

This tutorial assumes you have followed tutorials 1-1 and 1-2, if you haven’t – go and complete these now.

Ok, let’s open our project we made in the previous tutorial. To open a project follow these steps:

  1. Start XCode
  2. Click File > Open then navigate to your project folder. This will be in the directory you saved it to.
  3. In your project folder, click “Hello World.xcodeproj” and click the Open button.
  4. Your project should open in a new window. Another way of opening a project is by navigating to it in finder and double-clicking the .xcodeproject file. If you have had the project open recently, click File > Open Recent Project and look for the project you want in the list.

Now you should have your project open. Double-click “Hello World.m” to open it for editing. Feel free to run it again to remind yourself what the program does. Remember, you can do this by clicking the Build and Go icon.

 

Read the rest of this entry »

Tutorial 1-2: Hello World!

Posted by Henry On April - 12 - 2009 2 COMMENTS

Ok, you should now have installed the iPhone SDK on your mac. If you haven’t, follow the instructions in tutorial 1-1.

We will be using an application called XCode to build our applications, so fire it up now. (You can find it in the directory you installed the SDK to, if you can’t find it, use the search feature in the top-right corner of the screen.) Upon opening XCode, you should be presented with a splash screen welcoming you to XCode. Close this (and uncheck “show at launch” if you don’t want to see it again). Now follow these instructions to get started:

  1. Click File > New Project.
  2. In the left pane of the new window, choose Command Line Utility and then select Foundation Tool in the right pane. Now click the Choose button at the bottom of the window.
  3. You will now be asked to create a project file. This is where all the files you use in this project will be stored. Save it as “Hello World” in a folder you will remember. I saved mine in User/Documents/iPhoneDev/.
  4. You should now see the project window which is split into 3 parts. The pane on the left is used to organize and group all your project files, the top-right pane is for viewing all the files in a particular folder, and the bottom-right pane is used to preview a file’s contents. For now we only want to see any code documents, so click the Source folder in the left-pane.
  5. You should now see two files in the right pane. “Hello World.m” and “Hello World_Prefix.pch”.

Great! All set up and ready to start coding!

Read the rest of this entry »