开发者

Setting predicate to search in Core Data

I need to perform search Core Data entities in my app for iPhone.

In my Core Data I have an entity 'myEntity', that has two properties 'stringOne' and 'stringTwo'; both defined as NSString.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringOne contains[cd] %@", self.keyword4Search]; 
[fetchRequest setPredicate:predicate];

My code above only search entities that 开发者_高级运维contains keyword4Search in stringOne only.

What I need is to search entities that contains keyword4Search in [stringOne OR stringTwo].


I expect kind of

predicateWithFormat:@"stringOne or stringTwo contains[cd] %@", self.keyword4Search];

where should I look?


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringOne contains[cd] %@ OR stringTwo contains[cd] %@", self.keyword4Search, self.keyword4Search];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜