Objective-C 2.0부터는 세터와 게터 메서드(둘을 합쳐 '접근자 메서드'라고 한다.)를 자동으로 생성할 수 있다.
첫단계는 인터페이스 부분에서 @property 지시어를 사용하여 프로퍼티를 지정해 주는 것이다. 이 프로퍼티들은 보통 인스턴스 변수라고 부른다.
[Example Interface]
@interface Fraction: NSObject
{
int numerator;
int denominator;
}
@property int numerator, denominator;
@end
이제 numerator, denominator, setNumerator, setDenominator 같은 게터와 세터 메서드에 대한 정의가 포함되지 않는다. 이것들은 Objective-C컴파일러가 자동으로 생성(synthesize)해 줄 것이다.
[Example implementation]
#import "Fraction.h"
@implementation Fraction
@synthesize numerator, denominator;
@end