To remove duplicates in CoreData and automatically update in TableView, we need to use NSFetchedResultsController.
First, we need to create a fetch request where we set the "resultType" to "dictionaryResultType" and also set the "propertiesToFetch" array with the attributes you want to fetch. Then we use the "NSExpression" to get distinct value(s) for that column.
Secondly, we need to implement an NSFetchedResultsControllerDelegate to monitor any changes to the data and reload the tableview accordingly.
Here's the example code:
main.swift1620 chars39 lines
Note: Replace "EntityName" with the name of your entity and "attributeName" with the name of the attribute you want to fetch distinct values for.
gistlibby LogSnag