Trouble with negating Core Data NSPredicate relationships Trouble with negating Core Data NSPredicate relationships ios ios

Trouble with negating Core Data NSPredicate relationships


try this

NSPredicate *predicate = [NSCompoundPredicate notPredicateWithSubpredicate:[NSPredicate predicateWithFormat:@"ANY reviews.user = %@", self.user]];


[NSPredicate predicateWithFormat:@"NOT reviews.user = %@", self.user]


The problem is that you want to compare relationships in your predicate rather than attributes. Your User should have a unique attribute, such as name. I suggest that you use it in your predicate in the following way:

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];NSPredicate * p = [NSPredicate predicateWithFormat:@"ANY comments.user.name != %@", @"John Smith"];// NSPredicate * p = [NSPredicate predicateWithFormat:@"NONE comments.user.name == %@", @"John Smith"];request.predicate = p;