iPhone Development and a sample Objective C Program

Kiichi and I really liked the demo from apple about the iPhone SDK.

If you haven’t seen it, check it out@

http://www.apple.com/quicktime/qtv/iphoneroadmap/

We at ObjectGraph think the new app store feature will level the playing field for all developers, big(EA) and small(OG). Now its up to developers to create new applications and make them success stories. So We started developing in Objective C. With its kinda wierd syntax coming from C#, Java, ActionScript and Python, but here is my first try anyway :-)

I am creating a MyPoint class with a distance function that takes a reference of an another point.



#import 

@interface MyPoint : NSObject {

	int x;
	int y;

}

-(void) print;
-(void) setX:(int) a; // void setX(int a);
-(void) setY:(int) b;
-(int) getX;
-(int) getY;
-(double) distance:(MyPoint*) p;

@end

Implementation


#import "MyPoint.h"
#import 
#import 

@implementation MyPoint

-(void) print
{
	printf("(%d,%d)",x,y);
}

-(void) setX:(int) a
{
	x=a;
}

-(void) setY:(int) b
{
	y=b;
}

-(int) getX
{
	return x;
}

-(int) getY
{
	return y;
}

-(double) distance:(MyPoint*) p;
{
	return sqrt((x-[p getX])*(x-[p getX])+(y-[p getY])*(y-[p getY]));
}

@end

Main


#import 
#include 
#import "MyPoint.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	MyPoint *point1=[[MyPoint alloc] init];
	[point1 setX:10];
	[point1 setY:20];

	[point1 print];

	MyPoint *point2=[[MyPoint alloc] init];
	[point2 setX:10];
	[point2 setY:30];
	[point2 print];

	printf("Distance: %lf\n", [point1 distance:point2]);

	[point1 release];
	[point2 release];

	[pool drain];
    return 0;
}
By: gavi on: