使用@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