I've defined two properties with corresponding ivars and synthesized them:
@property (nonatomic,copy) NSString* title;
@property (nonatomic,copy) NSString* person;
Now in my implementation, I've the following custom getter for title
:
- (NSString*)title {
return (person) ? person : [title capitalizedString];
}
So the title
property depends on both the title
property itself and the person
property. I'd like to make this class KVO compatible, so I added:
+ (NSSet*)keyPathsForValuesAffectingTitle {
return开发者_StackOverflow中文版 [NSSet setWithObjects:@"person", nil];
}
Now my question: Do I have to add @"title"
to the set as well, to make sure changes of the title
property are observed, too? If yes, doesn't this create an infinite loop?
Or does KVO automatically depend on the property itself?
According to the docs, you don't put the 'title' property in the set. I presume it's assumed that all properties are, by default, dependent upon themselves.
精彩评论