A simple Objective-C Method Declaration and Definition

定義

- (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;
}
//

objective-c-intreface

Comments are closed.

Related URL:
  1. Garmin 310XT PK iPhone4 GPS location 精準度
  2. 2011 巴黎馬拉松 – 法國警局
  3. [open source] iPhone , UIImage and PhotosAlbum 上傳一個圖到 simulator 的相簿 PhotosAlbum sample code
  4. 試用 ADIDAS 的 micoach iPhone APP. 跑10K間歇 ( without heart rate monitor)
  5. sample iPhone screen snapshot
  6. [iPhone dev] 今天看到一個精巧的設計 / tableview / iPhone design pattern
  7. 幾個 iPhone dev 的 opensource site
  8. My iPhone 4 / iP 4
  9. @@ 是誰又亂丟箱子在我桌上啊. . .
  10. iPhone icon size / iPhone 人機介面建議守則