Reputation: 5650
I have a Core Data model like so:
ArticleCache:
- NSString *link
And I have some a custom object like so:
Article:
- NSString *linkString //NSString version of link
- NSURL *link
- NSString *title
I have an NSArray
of Article
s (articleList
below), and I have a Core Data store with ArticleCache
s.
I'm trying to retrieve the ArticleCache
s that have a matching link in my articleList
:
NSEntityDescription *articleCacheObjectModel = [NSEntityDescription entityForName:@"ArticleCache" inManagedObjectContext:backgroundContext];
// Setup the fetch request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:articleCacheObjectModel];
//search will return all items matching the link
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"link in %@", articleList];
[request setPredicate:searchPredicate];
NSError *error = nil;
NSArray *results = [backgroundContext executeFetchRequest:request error:&error];
When I run this, results
is always empty, despite that I know there are matching ArticleCaches
in the Core Data store. I know this because if I remove the predicate from the request, I get all the ArticleCache
s, and I can print out their respective link
s and compare them.
Any ideas?
Upvotes: 0
Views: 157
Reputation: 540105
The "link" attribute of the "ArticleCache" entity is a string, and in your predicate you try to test if this string is contained in an array of Article
objects. That will never match.
You can build an array of string URLs first, e.g.
NSArray *urlList = [articleList valueForKey:@"linkString"];
and then use that in the predicate:
[NSPredicate predicateWithFormat:@"link in %@", urlList];
Upvotes: 2