iphone core data - How to make a NSPredicate for NSFetchedRequest in this case?
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", ...];
精彩评论