小编nep*_*lim的帖子

在NSPredicates中使用关键路径

我有一个NSDictionary,其中包含(我的自定义)GTPerson对象.GTPerson有一个NSMutableSet *parents属性,我使用@property@synthesize.

在我的NSDictionary之外,我想过滤掉所有没有父母的GTPerson对象,即父母的数量是0.

我正在使用以下代码:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parents.count = 0"];
NSArray *np = [[people allValues] filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

当我执行此操作时,我收到以下错误:

[<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.'

为什么它试图调用countGTPerson而不是它的parents属性?

objective-c key-value-observing key-value-coding

4
推荐指数
1
解决办法
4616
查看次数