如何在 NSStrings 的 NSArray 上使用 NSPredicate 中的键路径?
有谁知道如何在 NSPredicate 中使用键路径?
我尝试使用键路径,但发生错误。
我想使用 "dictate like 'AAA'"
作为关键路径。
源代码:
- (void)Predictate{
dictate = [[NSMutableArray alloc]initWithObjects:@"AAA",@"BBB",@"CCC", nil];
NSPredicate *test = [NSPredicate predicateWithFormat:@"dictate like 'AAA'"];
NSMutableArray *result = [dictate filteredArrayUsingPredicate:test];
NSLog(@"%@",result);
}
这是错误消息:
2012-01-02 01:33:33.673 过滤器[1867:707] * 由于以下原因终止应用 未捕获的异常“NSUnknownKeyException”,原因: '[<__NSCFConstantString 0x1000022f0> valueForUndefinedKey:]: 这个 类不符合键指令的键值编码。'
Does anyone know how to use key-paths in NSPredicate?
I'm trying to use key-paths, but an error occurred.
I want to use "dictate like 'AAA'"
as key-path.
Source code:
- (void)Predictate{
dictate = [[NSMutableArray alloc]initWithObjects:@"AAA",@"BBB",@"CCC", nil];
NSPredicate *test = [NSPredicate predicateWithFormat:@"dictate like 'AAA'"];
NSMutableArray *result = [dictate filteredArrayUsingPredicate:test];
NSLog(@"%@",result);
}
This is the error message:
2012-01-02 01:33:33.673 filter[1867:707] * Terminating app due to
uncaught exception 'NSUnknownKeyException', reason:
'[<__NSCFConstantString 0x1000022f0> valueForUndefinedKey:]: this
class is not key value coding-compliant for the key dictate.'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“self LIKE 'AAA'”有效。已测试。
这是一个微妙的事实,您可以将
self
发送到 Objective-C 对象并获取指向对象本身的指针(尝试[obj Performselector:@selector(self)]
) 。这就是它的工作原理。"self LIKE 'AAA'" works. Tested.
It's kind of subtle fact that you can send
self
to Objective-C object and get the pointer to the object itself (try[obj performselector:@selector(self)]
). So that's how it works.