// gcc test.m -o test -framework Foundation #import <Foundation/Foundation.h>
@interface MyClass:NSObject {} -(NSString *) speak:(int) n; @end
@implementation MyClass -(NSString *) speak:(int) n { int i; NSMutableArray *mA; mA = [NSMutableArray arrayWithCapacity:n]; for (i=0; i<n; i++) { [mA addObject:@"woof"]; } return [mA componentsJoinedByString:@"-"]; } @end
int main(){ NSAutoreleasePool *pool ; pool = [[NSAutoreleasePool alloc] init]; MyClass *obj; obj = [[[MyClass alloc ] init] autorelease]; NSLog(@"%@", [obj description]); NSLog(@"%@", [obj speak:2]); NSString *s; int count = 3; SEL sel = @selector(speak:); s = objc_msgSend(obj,sel,count); NSLog(@"%@", s); [pool drain]; return 0; } |