使用@synthesize生成的setter是KVC compilant还是不是?我发现getter和setter生成的声明符合KVC,不应该调用这种方法吗?@合成属性和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"];
我正在测试生成的setter是KVO compilant的语句,这就是为什么我使用setter,而不是setValue itselt。我知道调用setValue的工作,但调用生成的setter不会在“测试”上调用setValue。 – Marcin