Friday, December 21, 2007

objective-c hello world

I just started learning objective-c and cocoa a few days ago, and here is how I wrote an overly complicated objective-c "hello world" application.

#import <objc/Object.h>

@interface MyClass : Object {

- (void) sayHello;

#import "MyClass.h"
#import <stdio.h>
@implementation MyClass : Object {


- (void) sayHello { printf("Hello, World!\n"); }

#import <objc/objc.h>
#import "MyClass.h"

int main() {
MyClass *anObject;

anObject = [[MyClass alloc] init];
[anObject sayHello];

return 0;

I compiled this using the following:
gcc -o hello -lobjc MyClass.m main.m