How to write a NSPredicate to obtain all items whose ids are in an array?
In my core data db, every item has a string id which is an url to indicate whom this item belongs to.
Now I have an array which contains, say, 200 owner urls (200 is just an example, it is dynamic in the app).开发者_如何学JAVA I wish to fetch all items that belong to the 200 own urls.
If only 1 owner url, I know how to write:
[NSPredicate predicateWithFormat:@"(ownerUrl == %@)", url]
What about an array of owner urls, say 200?
by the way, the core data I am using is sql. I think sql will ignore "IN" in NSPredicate?
Thanks
Try this :
NSSet *urls = [NSSet setWithObjects:@"url1", @"url2", @"url3", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"ownerUrl", urls];
精彩评论