开发者

iphone core data - How to make a NSPredicate for NSFetchedRequest in this case?

开发者 https://www.devze.com 2023-02-27 00:23 出处:网络
I have a large number of Items in the core data. Each Item has an attribute called \"Source\", which is a string, indicating the Source this item be开发者_高级运维longs to.

I have a large number of Items in the core data.

Each Item has an attribute called "Source", which is a string, indicating the Source this item be开发者_高级运维longs to.

When I fetch from the core data, I will fetch items from 10 sources (totally over 200 sources) each time and each time the 10 sources are randomly chosen before fetching.

How can I write the NSPredicate for this case?

If each time only fetch items from 1 source, it is easy:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"Source like %@", @"source1"];

But what if it is 10 sources and change over time? do I need to write like

NSPredicate *pred = [NSPredicate predicateWithFormat:@"(Source like %@) AND (Source like %@) AND...", @"source1", @"source3", ...];

Thanks


NSPredicate *p=[NSPredicate predicateWithFormat:@"source in %@", anArrayOfSourceStrings];


NSPredicate *pred = [NSPredicate predicateWithFormat:@"Source in (%@, %@, %@, %@, ...), @"source1", @"source3", ...];

0

精彩评论

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

关注公众号