I have a UITableView which displays historical data. This is broken up into one section per day. Each day can have multiple things happening (eg. during a certain day I slept, ate some food, did some exercise, etc). Each “thing” is represented by a different entity. So going off the previous example, I have Day, Sleep, Food and Exercise entities. Sleep, Food and Exercise all have the Day entity as a parent, through a one-to-many relationship.
Currently what I am doing is loading all the Day entities, then for each Day I will load the Sleep, Food and Exercise entities into one single array, and sort it by date. Needless to say this gets slow when there is a lot of data.
Is it possible to use a NSFetchedResultsController in this instance?
This is just a guess, but I think the following would work:
EDIT – I have just verified with a simple case, that this does work
Have all of your event entities (Sleep, Food, Exercise) inherit from a base class entity (you could call it something like “Event”) and then use the following when you are setting up your NSFetchRequest that your NSFetchedResultsController will use:
In theory, this would cause your results controller to return all of your existing entities that inherit from Event. You could also put the relationship to Day in the base class (Event) because all your subclasses have that in common. Also, you would need to specify a predicate for your fetch request to only grab the events for the specific Day you are after.
Let me know if this works!