@synthesizeで生成されたセッターはKVCコンパイラであるかどうか?ゲッターとセッターがKVCに準拠しているという声明がありましたが、このメソッドの1つを呼び出すべきではありませんか?@synthesizedプロパティとKVC
@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
としてそれをテスト:KVOのために:
testing *t = [[testing alloc] init];
[t setPhone:@"55555555"];
私はsetterを生成するステートメントはKVOコンパイルであるため、これはsetValueではなくsetterを使用する理由です。私はsetValueを呼び出すことは知っていますが、生成されたsetterを呼び出すと、 "testing"でsetValueが呼び出されません。 – Marcin