Reputation: 9273
Hello i have this Core data:
then i do this:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"MyDate" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
now i want use the NSPredicate to take only the MyDate with the Task for the taskes relationship that have isView = NO and the taskDate <= today, and that the count of all Task for each MyDate is > 0...there is a way?
Upvotes: 3
Views: 531
Reputation: 827
I don't have enough points to comment, so jumping off of Nikita's answer, all you need to do is the following:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY taskes.isView = NO AND ANY taskes.taskDate <= %@", todayDate];
One way you can get today's date (there might be better ways):
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString *dateString = [dateFormat stringFromDate:date];
NSDate *todayDate = [dateFormat dateFromString:dateString];
Upvotes: 2
Reputation: 5966
Use [NSPredicate predicateWithFormat:@"taskes.@count>0 AND (ANY (taskes.isView = NO AND taskes.taskDate<%@)",today]; "
Not sure,but maybe it would work
Upvotes: 0