<

Go Premium for a chance to win a PS4. Enter to Win

x

First iPhone Application

Published on
12,721 Points
6,121 Views
6 Endorsements
Last Modified:
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Important pre-programming comments:

I’ve never tried other options, only those recommended by Apple:

 1. Intel-based Mac computer running Snow Leopard
 2. iPhone SDK 3.2 installed on this computer

Also, this article discusses only how to create and simulate a simple iPhone app,
it does not get into the details of how to load and test on an actual iPhone.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

The iPhone Software Development Kit (SDK) can be downloaded for free from the Apple developer portall. You need to register yourself, but it is free. The installation is simple - agree with everything proposed by the installation wizard. When the installation is done, you can delete the installation package from your desktop.

Once you have the SDK, we can start.

ToDo

 1. Launch Xcode.
The Xcode application, by default, is installed into “/Developer/Applications” folder. You can find it in Finder and move the application to your Doc for faster access in the future.

 2. Create a new iPhone Window-based application.
In the File menu of Xcode select “New Project...” item. In the new project wizard choose iPhone OS in the left panel and Window-based application template in the right. Press “Choose” button in the right-bottom corner. In the next window that appears on the screen after, type the project name “First”. Click on Save button. Now you see the project window, it contains all project source files.

 3. Modify the application delegate class.
Find FirstAppDelegate.h file in the left panel named as “Group & Files” in the project window. Click on the file name and the file is opened in the editor. Add three lines to this file. I marked these lines with the comment in the code below:
#import <UIKit/UIKit.h>

@interface FirstAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    
    // add the following line to the generated code
    UITextField *text;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

// add the following 2 lines to the generated code
@property (nonatomic, retain) IBOutlet UITextField *text;
- (IBAction) buttonClicked:(id)sender;

@end

Open in new window


Find FirstAppDelegate.m file in the Classes group, in “Group & Files” panel and click on the name to open it (Alt-Cmd-Up keyboard shortcut switches between the header and implementation files). Add the code marked with the comment:

#import "FirstAppDelegate.h"

@implementation FirstAppDelegate

@synthesize window;

// Add this block
@synthesize text;

- (IBAction) buttonClicked:(id)sender
{
	[text setText:@"Hello"];
}
// End of the new block

- (BOOL)application:(UIApplication *)application 
             didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   // Override point for customization after application launch
    [window makeKeyAndVisible];
    return YES;
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

Open in new window


 4. Save the project.
Hold the Control button on the keyboard and press S. Or, click on Save item in the File menu.

 5. Arrange the application GUI in Interface Builder.
Find MainWindow.xib file in the “Group & Files” panel. It is in the Resources folder. Click on it to open Interface Builder. On the left side you see the Library window. It contains all Cocoa Touch controls. There is a search field in the bottom of this window. Type “push” there to find the Push Button in the Library. Drag this control to the prototype window - an empty window in the middle of your screen now, the window has title “First”.
Control-drag from the Push Button in the “First” window to the FirstAppDelegate object in the Document window below. When you release the mouse, in the popup menu select “-buttonClicked” item.
Find Text field in the Library - type “Text” in the search field. Drag Text Field to the application window. Connect the application delegate with the Text Field - hold Control and  drag with the mouse from the application delegate object to the text field. When you release the mouse button above the text field, select “text” item in the popup menu that appears.

 6. Save your work in the Interface Builder.
Same as in the editor: hold Command keyboard button and press S or via the File menu of the Interface Builder.

 7. Build and Run.
Switch to the source code editor: click on the Xcode project window. Select iPhone SDK Simulator as the active SDK and debug mode in the combo above the “Group & Files” panel. Find “Build and Run” button in the top toolbar. If you did everything right in the source code and in the Interface Builder, you’ll see your application running in the iPhone Simulator window. Press on the button, check that you see the text “Hello” in the text field.
Here are few screenshots to illustrate the scenario above.
New Project Wizard
Xcode IDE
Prototype Window in Interface Builder
Set build configuration
Application running in iPhone Simulator
Recommendations

I'd like to propose a way I used to learn Objective-C and Cocoa. A few of my friends have tested this approach and found it helpful.

 1. Begin from the book “Programming in Objective-C 2.0” Stephen G. Kochan. With this book you will write small command-line tools for Mac OS and will learn the basics of Objective-C. You don’t have to finish this book, even a half of that will allow you to go up to the next step.

 2. You can find a great tutorial on Mac OS Reference Library - Currency Converter. It will take you few days (it is better if it will be few days) to read and understand everything, to implement this Currency Converter application. This tutorial also explains the basic principles of Objective-C. It will balance and arrange this beginning knowledge in your head.  After this step you can make simple GUI applications yourself. Find few ideas, something that you need in your day-to-day work, a decimal-to-hexadecimal converter for example, and implement it.

 3. At this stage you already beginning to understand the technical articles about Objective-C, Mac OS and iPhone programming. You can find many technical resources in the internet. A few of them are listed in the end of this article.

 4. Now it’s time again for a book. I think the best book (for now) about Objective-C 2.0 and Cocoa is “Cocoa and Objective-C Up and Running” from Scott Stevenson. This book teaches you to develop in Cocoa for Mac OS, but always shows the differences between the Cocoa and Cocoa Touch (iPhone SDK). The author found the best words to explain everything about Objective-C and Cocoa.
 
 5. You are ready to program for the iPhone. Everything iPhone SDK related should be clear for you now. There are a lot of books about the iPhone development, but most of them will be a short versions of the books I have mentioned. The differences between the Mac OS development and iPhone development are not that big. At least, in the beginning it seems to be not that big. I can also say that Cocoa Touch is like a small version of Cocoa.  

This plan makes sense if you already have an Intel-based Mac computer, it already has Snow Leopard, you have registered yourself on the Apple developer portal, downloaded and installed iPhone SDK.

I can't promise that this will be as short and simple as you may wish. It is likely to take longer than a month or two. It is not because Objective-C is a difficult programming language or Cocoa is a very rich framework to learn. It’s because you’ll love this language and this framework same way as you love your iPhone. Along the way you will find other attractive topics to learn, such as AppleScript or bash. You may wish to work with iPhoto or with a dozen of other famous Mac applications. It is an interesting path, and you are likely to enjoy it.

References

 1. Mac OS Reference Library
 2. CocoaMyGirlFriend
 3. Cocoa with Love
 4. iPhone developers:tips
 
6
Comment
Author:pgnatyuk
  • 2
3 Comments
 

Expert Comment

by:Graeper
Help - In the Cocoa Touch Controls, I can find a Push Button
0
 
LVL 33

Author Comment

by:pgnatyuk
What do you mean?
In case you need a help please ask in the Objective-C Zone.
0
 

Expert Comment

by:Graeper
I thought I was in the Objective-C Zone.  In Section 5. of your illustration above, you say "Find MainWindow.xib file in the “Group & Files” panel. It is in the Resources folder. Click on it to open Interface Builder. On the left side you see the Library window. It contains all Cocoa Touch controls. There is a search field in the bottom of this window. Type “push” there to find the Push Button in the Library. Drag this control to the prototype window - an empty window in the middle of your screen now, the window has title “First”."

I did everything you said but i couldn't find a Cocoa Touch Control labeled "push"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month