I have 2 entities:
Performance.start (NSDate) Location.coordinates
Performance.end (NSDate) Location.name_extern
Performance.location <<--> Location.performances
I have a NSFetchedResultsController for my UITableView set up with the following code:
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"location.name_extern"
cacheName:nil];
So the data is divided into sections by locations (their names).
Now I have a variable selectedTime of type NSDate and want to fetch (with a single fetch if possible) the following:
- Only 2 Performances per Location:
- The Performance that is running
(selectedTime BETWEEN {start, end}) - The Performance that will start after the one that is running at the selected time
- The Performance that is running
I’m really lost here :-/ Even if you could just give me the SQL statement for such a fetch/query I would at least know which direction to head..
Duh.. I think I found the final solution ..
The fetch is pretty simple:
With the following predicate:
And here’s how I solved the “only 2 per location/section” part:
Thanks for trying though André!