Objective C 2.0에 등장한 개념으로
제일 중요한 목적은 모든 프로그래머의 로망인 타자수 줄이기 (농담)
헤더
@interface babo : NSObject {
NSString *string;
int i;
}
@property(nonatomic, retain) NSString *string;
@property int i;
@end
소스
@implementation babo
@synthesize string;
@synthesize i;
@end
property 뒤에 아무 것도 안 쓰면 무제한 접근이 가능하다. 쓰기를 막고 싶으면
@property(readonly) int i;
그 외에 몇 가지 더 있는거 같다.
이렇게 해 두면 getter/setter 메서드가 비록 없지만
b = [[babo alloc] init];
[b setI:100000];
이런 짓이 가능하다
물론
j = [b i];
도 된다.
property를 안쓰면

댓글을 달아 주세요