@synthesizeで生成されたセッターはKVC準拠である必要がありますか?生成されたゲッターとセッターはKVCに準拠しているというステートメントを見つけましたが、このメソッドの1つを呼び出すべきではありませんか?
@interface testing : NSObject
@property (nonatomic, retain) NSString *phone;
@end
実装:
@implementation testing
@synthesize phone;
- (id)init {
self = [super init];
return self;
}
// none of these is called with dot syntax, or setter setPhone
- (void)setValue:(id)value forKey:(NSString *)key
{
NSLog(@"%@",key);
[super setValue:value forKey:key];
}
-(void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
NSLog(@"%@",keyPath);
[super setValue:value forKeyPath:keyPath];
}
@end
そしてそれをテストします:
testing *t = [[testing alloc] init];
[t setPhone:@"55555555"];