开发者

KVO for dependent property depending on itself

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜