I'm trying to find an object matching a string and a set of objects. My predicate looks like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@ and individuals CONTAINS %@", name, individuals];
I'm not getting any hits. Although I know there is an entity matching the name and individuals set.
What is wrong with my predicate?
EDIT: I've managed to do some progress. The problem now is if I try to find a group which has an existing group name and existing contacts ie groupname = "test" and individuals.name = "john doe" and individuals.contactInfo = "123" it will find me this group correctly but if I have a group with the same groupname and same contact + another contact it will also find me this group which I do not want.
I only want the group which matches exactly the predicate.
I'm now using subpredicates by doing this:
NSMutableArray *subPredicates = [NSMutableArray initWithCapacity:5];
// Add group name to predicate
[subPredicates addObject:[NSPredicate predicateWithFormat:@"name == %@", name]];
for (NSDictionary *contactInfo in individuals) {
NSString *name = [contactDict objectForKey:@"name"];
NSString *contactInfo = [contactDict objectForKey:@"contactInfo"];
NSPredicate *individualPredicate = [NSPredicate predicateWithFormat:@"ANY individuals.name LIKE %@ AND any individuals.contactInfo LIKE %@", name, contactInfo];
[subPredicates addObject:individualPredicate];
}
NSPredicate *individualsPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates];
Group *group = // do the fetch with the predicate