In this topic I will show how to write a simple application for the iPhone using the official SDK. Get it easy, you need:
1. Intel-based Mac (although it also works on PowerPC, but after some gestures)
2. iPhone SDK. I will write on beta 2. You can get the latest version by registering on developer.apple.com. Beta 2 can be found in torrents
HelloHabr
so as not to strain the mosk we will do the simplest thing: the application will only show the habr logo. Open XCode (required in
32-bit mode) and create a new Cocoa Touch application:

Let's call it HelloHabr and save it to the desktop.
The project creation wizard has already done it for us. Let's look at the contents of main.m:
#import <UIKit / UIKit.h>
')
int main (int argc, char * argv [])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// since it is impossible to use garbage collection in an iPhone, we use autorelease pool to make life easierint retVal = UIApplicationMain (argc, argv, nil, @ "HelloHabrAppDelegate");
// to start the application, you need to call this function. @ "HelloHabrAppDelegate" - class to which control will be transferred[pool release];
return retVal;
}
Now let's take a look at HelloHabrAppDelegate.h:
#import <UIKit / UIKit.h>
class MyView;
interface HelloHabrAppDelegate: NSObject {
UIWindow * window;
// main application windowMyView * contentView;
// an instance of the MyView class (it was also created automatically).}
// so that you can access window and contentView through a point, rather than write get and set. ObjC 2.0 Feature@property (nonatomic, retain) UIWindow * window;
@property (nonatomic, retain) MyView * contentView;
endand on HelloHabrAppDelegate.m:
#import "HelloHabrAppDelegate.h"
#import "MyView.h"
@implementation HelloHabrAppDelegate
// these directives mean that when compiling instead of calls through., enter getters and setterssynthesize window;
synthesize contentView;
// function delegated by UIApplication- (void) applicationDidFinishLaunching: (UIApplication *) application {
// Create the main windowself.window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] autorelease];
// create contentViewself.contentView = [[[MyView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]] autorelease];
// add our contetntView to the main window so that it is displayed[window addSubview: contentView];
// make the main window visible[window makeKeyAndVisible];
}
- (void) dealloc {[contentView release];
[window release];
[super dealloc];
}
endThe little mat.part is finished, let's start writing the application. Save the logo to the folder with the application. Then we drag it from the folder to the Resources folder of our project in the Xcode window:

Now let's add to the MyView class a new “habrView” field of the “UIImageView *” type, i.e. MyView.h will look like this:
#import <UIKit / UIKit.h>
interface MyView: UIView {UIImageView * habrView;
}
endand now we define the init and dealloc procedures in the MyView class:
#import "MyView.h"
@implementation MyView
- (id) initWithFrame: (CGRect) frame {if (self = [super initWithFrame: frame]) {
// background color is black[self setBackgroundColor: [UIColor blackColor]];
// create a new object with the image of the habr logoUIImage * image = [UIImage imageNamed: @ "habr.gif"];
// create a component that will display the logoself-> habrView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, [image size] .width, [image size] .height)];
[habrView setImage: image];
[habrView setCenter: [self center]];
[image release];
// add a component to display the habr logo on the form[self addSubview: self-> habrView];
}
return self;
}
- (void) dealloc {[self-> habrView dealloc];
[super dealloc];
}
endEverything. Compile, run and get what we wanted:

And now the method of creating applications for the lazy. Dashcode can create web applications for the iPhone and iPod Touch. Open Dashcode and select RSS as a preset. Go to the Page Attributes tab, set the Page Title: "Harbrahabr RSS", Feed URL: "feed: //habrahabr.ru/rss/main/". Then go to the “Harbrahabr RSS” tab (the designer opens) and change the “My RSS Feed” message to “Habrahabr RSS Feed”:

Click Run and get Habr's RSS reader:

In principle, everything. Feedback, suggestions, suggestions are waiting in the comments
Upd: slightly corrected formatting, the code reads better, but far from ideal