14
Jul

Come to/Login to the Mac OS-X shell prompt via the Terminal application or via SSH from a remote client. In the example I have used nano text editor to create these Objective C files using the Cocoa foundation framework

File: hello.h
#include <Foundation/Foundation.h>

@interface Hello: NSObject
{

}
- (void) sayHelloTo: (NSString *)name;

@end

File: hello.m

#include <Foundation/Foundation.h>
#include "hello.h"

@implementation Hello

- (void) sayHelloTo: (NSString *)name
{
NSLog(@"Hello World, %@", name);
}
@end

File: main.m

#include <Foundation/Foundation.h>
#include "hello.h"

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

id speaker;
NSString *name = @"GNUstep ... Sree";
speaker = [[Hello alloc] init];
[speaker sayHelloTo:name];

[speaker release];
[pool drain];
return 0;
}

Command to compile:
gcc -framework Foundation main.m hello.m -o hello

Command to run:
./hello

Output:
2010-07-14 15:57:39.459 hello[5325:903] Hello World, GNUstep ... Sree

Sree
Posted by on 14 Jul 2010 by Sree in Objective C

Add reply

*