The compile command for this program(using the GNU compiler) would be:
gcc -lobjc main.m printer.m -o test
// This will create a Printer object, set it's string and tell it to print #import "Printer.h" void main() { id printer = [[Printer alloc] init]; [printer addStringValue:"Hello World!"]; [printer print]; [printer free]; }
#import < objc/Object.h> @interface Printer : Object { char buffer[100]; } - init; - addStringValue:(const char*)astring; - print; - clear; @end
#import "Printer.h" @implementation Printer - init { [super init]; [self clear]; return self; } - addStringValue:(const char*)astring { strcat(buffer, astring); return self; } - print { printf("%s\n",buffer); [self clear]; return self; } - clear { strcpy(buffer, ""); return self; } @end