Reputation: 124
Lots of information on NSDates about the place, but I haven't found a clear solution to this.
I have a list of Event
entities, each with potentially many EventSessionTime
s.
Event
<--->> EventSessionTime
In 1 table view I want to display a unique list of days that have Events
, in another table view I want to show the events on a particular day (ordered by time).
To achieve this I currently have 2 NSDates - a day and time - and some overly complicated searching/sorting. I want to remove this redundant information.
With that in mind, how can I:
1) Finding all UNIQUE days with events, no concern about specific time
2) Finding all EVENTS on a particular day (duplicates fine here)
Any tips on how to better achieve this would be great.
Thanks.
Upvotes: 0
Views: 867
Reputation: 124
I now have the following relationship. Still have redundant date information..
Event
<--->> EventSessionTime
<<--> EventDay
1) Finding all UNIQUE days with events, no concern about specific time
I can create specific dates where I know the time. The localised nature of my application means I can do this safely.
...
[NSEntityDescription entityForName:@"EventSessionTime" inManagedObjectContext:self.managedObjectContext];
...
NSArray *res = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
[self myResultArray:[res valueForKeyPath:@"@distinctUnionOfObjects.eventDay.day"]];
You can infer my attribute and relationship names.
2) Finding all EVENTS on a particular day (duplicates fine here)
I use the following predicate to find all events on the specified day with. It does not return duplicates
[NSPredicate predicateWithFormat: @"(SUBQUERY(eventTime, $x, $x.eventDay.day == %@).@count > 0)", <the day selected from the previous list>];
Upvotes: 2