NSPredicate 用于获取字符串中的关键字
在核心数据中,我有一个名为关键字的实体,其属性为“文本”。我想找到特定字符串中包含的所有关键字对象。
我尝试过:
[NSPredicate predicateWithFormat:@"%@ contains[c] text", myString];
但是那会崩溃。好像只有反过来才有效。
In core data I have an entity called keyword with a property 'text'. I want to find all keyword objects that are contained in a particular sting.
I tried:
[NSPredicate predicateWithFormat:@"%@ contains[c] text", myString];
But that crashes. It seems like if it will only work if it's reversed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
谓词适用于实体,因此您的谓词被颠倒了。由于实体的文本属性包含单个单词,因此您需要将字符串拆分为多个单词,然后测试:
The predicate works on the entity, so you have your predicate reversed. Since your entity's text property contains a single word, you'd split the string into multiple words and then test:
我认为你正在做相反的方向。
试试这个。
I think you're doing in reverse direction.
Try this.