【发布时间】:2009-07-31 15:08:44
【问题描述】:
我有一个包含(我的自定义)GTPerson 对象的 NSDictionary。 GTPerson 有一个NSMutableSet *parents 属性,我在其上使用@property 和@synthesize。
在我的 NSDictionary 中,我想过滤所有没有任何父母的 GTPerson 对象,即父母的数量为 0。
我正在使用以下代码:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parents.count = 0"];
NSArray *np = [[people allValues] filteredArrayUsingPredicate:predicate];
执行此操作时,我收到以下错误:
[<GTPerson 0x18e300> valueForUndefinedKey:]: this class is not key value coding-compliant for the key count.
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GTPerson 0x18e300> valueForUndefinedKey:]: this class is not key value coding-compliant for the key count.'
为什么它试图在 GTPerson 上调用 count 而不是在其 parents 属性上?
【问题讨论】:
标签: objective-c key-value-observing key-value-coding