1

I have a large data set of objects, made up of 2 large-ish subsets.

  • Set 1 has about 10,000 objects in it.
  • Set 2 has about 70,000 objects in it.
  • The object sets have many-to-many relationships between them.
  • There are also "favorites" subsets for both sets.

Before I display set 1 or set 2, I will have a subset from the other set to drive my query/fetch.

Let's say:

  • I have selected 10 objects from set 1.
  • I would like to display set 2.
  • I'd like set 2 to be grouped into 3 sections:

    1. Section 1 would be objects in set 2 that have relationships with the 10 selected objects from set 1.
    2. Section 2 would be objects in the "favorites" subset that are NOT in #1.
    3. Section 3 would be the rest.

So, conceptually, I have the following steps (again, given 10 selected objects from set 1 and a "favorites" subset from set 2):

  1. Figure out which objects in set 2 correspond to the selected objects from set 1.
  2. Set #1 aside and remove them from the overall set (but only for this display).
  3. Figure out which objects are left in set 2 that are also in the "favorites" subset.
  4. Set #2 aside and remove them from the overall set (again, only for this display).
  5. Figure out which objects are left.

At the end of this, I'd like to display the 3 sections in a UITableView.

I saw this question, but I wasn't sure whether the supplied answers were:

  1. Still valid (it's been almost 7 years since the question was asked)
  2. Valid for my use case. (Would the calculated method return a section number? If so, would I have to pass in both subsets on which I am doing my filtering? How is that going to perform with such large data sets?)
mbm29414
  • 11,558
  • 6
  • 56
  • 87
  • A couple of questions: a) do you need the insert/update/delete functionality that a fetchedResultsController provides? (If not, then three separate fetches, with complementary predicates, might serve you better. Bear in mind also that an FRC for Set 2 will not respond to changes to objects in Set 1, so there will always be an issue in keeping the TV up to date.) b) do you want the section to appear, even if there are no matching items? (If so, it rules out using a single FRC to provide the sectioning - but you might be able to use three FRCs, one for each section.) – pbasdf Dec 30 '17 at 09:33
  • @pbasdf Thank you for the reply. a) I do not need insert/update/delete functionality. The data for a given `UITableView` is static. The data might change *between* 2 different instances of displaying the data, but it doesn’t need to be “live”, if that makes sense. b) This is a good question. I don’t think it will ever be the case that a section will be empty, but I would say, no, if a section is empty, it should not appear. So, does that help me get the data down to a single FRC? – mbm29414 Dec 30 '17 at 16:06
  • On reflection, I don't think a single FRC will achieve what you want. Whilst it will be possible (if tricky) to define a custom method to use in the sectionNameKeyPath, defining a corresponding sort descriptor for the underlying fetch will not be possible: CoreData fetches can only be sorted by one or more attribute/keyPath values. So I think three separate fetches might be your best bet. – pbasdf Dec 30 '17 at 16:29

0 Answers0