使用@synthesize 生成的setter 是否应该与KVC 兼容?我发现生成的 getter 和 setter 符合 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
并通过以下方式对其进行测试:
testing *t = [[testing alloc] init];
[t setPhone:@"55555555"];