定義
- (void) sayHello: (NSString*) name;
implementation :
- (void) sayHello: (NSString*) name { NSMutableString *message = [[NSMutableString alloc] initWithString:@"Hello there "]; [message appendString:name]; NSLog(message); [message release]; } //
simple.m 宣告 sayHello method:
#import "Simple.h" @implementation Simple - (void) sayHello: (NSString *) name { NSMutableString *message = [[NSMutableString alloc] initWithString:@"Hello there "]; [message appendString:name]; NSLog(message); [message release]; } @end //
simple.h
#import @interface Simple : NSObject { } -(void) sayHello: (NSString *) name; @end //
main 呼叫 sayHello method:
#import #import "Simple.h" int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Simple * mySimple = [[Simple alloc] init]; [mySimple sayHello:@"James"]; [mySimple release]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } //