How to learn to develop iPhone apps.

Many, many people always are curious about how to start developing iPhone and iPad apps. So, here is my guide to how I learned, and hopefully it will help!

First, you need the following:

  1. A fairly recent Apple Computer running Snow Leopard or Lion.
  2. Xcode with the iPhone SDK installed. (Its available in the App Store.)
  3. If you wish to do on device testing (installing and testing the apps you made on your own iPod, iPhone, or iPad) you will also need to buy an Apple Developer Account for $99 a year. Its completely worth it. http://developer.apple.com/programs/ios

After you get Xcode installed, I would start setting simple goals for yourself. Additionally, focus on an end goal instead of focusing on how to “learn to program.” So, instead of setting a goal like learning how Objective-C differs from C++, make a goal like creating an app with one button that allows you to switch the color of the view’s background. Learning Objective-C will progress as you work toward your goal.Before you start developing your first app, you should learn the basic template/setup of an iOS project.

When you first create a project, in this case, you should do the following when you go to create a new project:

  1. Select Single View Application
  2. Uncheck “use Storyboard”
  3. Make sure “use automatic reference counting” is checked (we will cover this later)
After you do that, you should see a new project created, and the left side bar should resemble the image above.
Here is the BASIC template for each view on the iPhone:
  • The header (.h) file. This contains the basic outline of your view.
  • The implementation file (.m) contains the main active components of your view.
So, lets create a simple app that has a button that changes the content of a text on the screen.
Things we will need:
  • UIButton
  • UILabel
  • IBAction (basically the method that is called when a button is tapped.)

In the header file (.h) file make sure you enter this:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {

UIButton *button;
UILabel *labelText;

}

@property (strong, nonatomic) IBOutlet UILabel *labelText;
@property (strong, nonatomic) IBOutlet UIButton *button;

@end

Next, we will add a method that will allow the content of the UILabel we just created to change once the button is pressed. Add

– (IBAction) didPressButton;

 

between the last @property and the @end.

After you finish that, open up the implementation file (.m)

At the top make sure you add the @synthesize.

So, it should look like this:

@implementation ViewController

@synthesize labelText, button;

 

This allows the implementation file to know about the two variables you created in the header file.

To begin, there are a few things you should know about in the implementation file.

First, you should see an empty method that looks like this:

– (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

This method, viewDidLoad, is called once when the view is first loaded into memory.
So, for the sake of this app, lets set the inital value of the text in the label in this method.

Inside the viewDidLoad method you should add

[labelText setText:@”hello!”]

 

This will set the body of the label to hello! when the view is initially loaded.

Next, lets add the method we created in the header file. So, after viewDidLoad you should add

– (IBAction) didPressButton:(id)sender {

[labelText setText:@”button pressed!”];

}

This will be called once you press a button on the screen.

So, now the code side of our app is completed. We need to link this up to the interface.

On the left panel of your screen you should click ViewController.xib.

You should then drag a UILabel and a UIButton onto the screen.

 

Now we need to link these components to our code.
Right click the top cube called files owner. Once you do this you should see the label and buttons we created, as well as the method.
Drag a line from the little circle next to the name of the variable onto the corresponding label or button on the screen you just added. Finally, drag a line from the method we created onto the button. Once you do that, another black box should appear. Select “touchUpInside”.

Be sure to save everything and now run it. The project should work!

 

3 thoughts on “How to learn to develop iPhone apps.

  1. Hey there,

    I went through this and there’s a mistake in the code.

    You write did PressButton for the method definition in the .h

    I think the space threw off the code. Took me a while to find that.

    Thanks for throwing this up, though!

    Tyler

  2. Thanks , I’ve just been looking for information about this topic for a long time and yours is the greatest I’ve came upon till now. However, what about the bottom line? Are you certain about the source?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s