0

I am initialising NSFetchedResultsController with following code

self.fetchedResultsController = NSFetchedResultsController(
            fetchRequest: request,
            managedObjectContext: context,
            sectionNameKeyPath: "article.name",cacheName: nil
        )

Here articles can have same name.So article.name sectionNameKeyPath is non unique.In this case fetchedResultsController will have only single section.

How can I handle multiple section with same section name?

Mannopson
  • 2,634
  • 1
  • 16
  • 32
UIBittu
  • 215
  • 2
  • 13
  • then, what is the need for showing them as sections?, why don't you just show them as rows? – Ravi Feb 10 '17 at 07:10
  • @raki see I have 5 components ( entity ) in which 2 are related to Article A and rest related to Article B .So my section names will be Article A,Article B.But If I am changing name of both article to X then I will one section thats the problem ! – UIBittu Feb 10 '17 at 07:28
  • can you show the data model structure? – Ravi Feb 10 '17 at 07:37
  • You should use unique id of article as sectionNameKeyPath – jia ma Feb 10 '17 at 08:06
  • @jiama What if the section names are non unique.In my case user can change the name, so there is possibility of having two sections with same name. – UIBittu Feb 10 '17 at 08:46
  • @UIBittu Maybe you need add unique id for article – jia ma Feb 10 '17 at 08:55
  • @jiama I have unique id for article but I need to display the article name as section title.If I am using the NSFetchedResultsController ,how can I achieve that ? – UIBittu Feb 10 '17 at 10:44
  • @UIBittu If they are 5 article, you want to display them in 5 sections without grouping them? – Sahana Kini Feb 16 '17 at 07:27

1 Answers1

0

For the sectionKeyPath return a UUID for the section (article.articleId or the like). Then when you display the title for the header in section don't display the named returned from the fetchedResultsController (self.fetchedResultsController.sections[section].name), rather get the first object in the section and figure out what you really want to display based on that (self.fetchedResultsController.sections[section].objects.firstObject.article.name).

Jon Rose
  • 8,373
  • 1
  • 30
  • 36