ObjectiveC:Synthesize
자동으로 Setter와 Getter를 생성한다.
How to use
헤더 파일:
#import <Cocoa/Cocoa.h>
@interface Model : NSObject {
NSString *data;
}
@property(copy, readwrite) NSString *data;
@end
구현 파일:
위와 같이 작성한 코드는 이제 다른 객체에서 다음과 같이 사용할 수 있습니다.
#import <Foundation/Foundation.h>
#import "Model.h"
int main(int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Model * model = [[Model alloc] init];
// synthesize를 통해 생성된 setter, getter사용법
[model setData:@"Hello Eye!"];
NSLog([model data]); // Hello Eye!
// dot 문법 사용하기
model.data = @"Bye Eye!";
NSLog(model.data); // Bye Eye!
[pool drain];
return 0;
}