My Core Data model looks like this:
article <--->> category
Is it even remotely possible to use NSFetchedResultsController to produce a UITableView that looks something like this?
Category 1
- Article A
- Article B
- Article C
Category 2
- Article A
- Article D
- Article E
- Article F
Category 3
- Article B
- Article C
Specifically, I’m interested in the (edge?) case where each UITableView section has a unique title (eg, “Category 1”, “Category 2”), but the same object can exist in multiple sections (eg, Article A exists in both Category 1 and Category 2).
I have scoured Apple’s Core Data docs and have spent two days perusing questions here, but alas, no luck even finding out whether this is possible, let alone how to implement it. Thanks for any help or pointers to a previously answered question. I certainly couldn’t find it.
Yes, it’s easy, though there are a million ways to do it.
Your view controller should be the “data source” of the
UITableView, and returns information about the number of rows there are and then the contents of each individual row.There is a concept of a “section” in a tableview, you might choose to have one for each category.
For example, you could create an
NSFetchedResultsControllerto find the categories you want to display, and use that to populate the table view sections, and then each category would have an articles many-to-many relationship, to populate the rows in each section.Something like this should get you started (assuming your category and article entities both contain a
titleproperty):You can read the documentation on these methods to figure out how to customise it further.