Use NSPredicate to Retrieve Information from Master Data from a Relationship

Hi, I have Core data:

enter image description here

then i do this:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription 
                           entityForName:@"MyDate"  inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

now I want to use NSPredicate to only accept MyDate with a task for task relationships that have isView = NO and taskDate <= today, and that counting the entire task for each MyDate is> 0 ... is there a way?

+3
source share
2 answers

I don’t have enough points for comments, so, bouncing off 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 to get today's date (there may 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];
+2
source

Use [NSPredicate predicateWithFormat:@"taskes.@count>0 AND (ANY (taskes.isView = NO AND taskes.taskDate<%@)",today]; " Not sure, but maybe it will work

0
source

All Articles