CoreData find indexPath of entry

563 views Asked by At

I have an CoreData model with the entity Person and an attribute called name. I store 4 strings into name (Pete, Paul, Dan and Jo). Now I'd like to find out which indexPath Paul has. How can I do this?

My CoreData model: enter image description here

1

There are 1 answers

2
Mundi On

To display Core Data entities in a table view, you should use a NSFetchedResultsController. One requirement is that the entities you fetch must be sorted, so the index path is unequivocal.

To find the index path of a Person object in your fetched results controller driven table view, use

let indexPath = self.fetchedResultsController.indexPathForObject(person)!