CoreData: How to fetch a specific object using a predicate

后端 未结 4 1175
不知归路
不知归路 2020-12-30 03:13

The situation:

I fetch a complete table from my sqllite core data database and show it in a TableView like this:

NSEntityDescriptio         


        
4条回答
  •  伪装坚强ぢ
    2020-12-30 03:50

    When you build the table you do so either with an array returned by a fetch or by the implicit array inside a NSFetchResultsController. Therefore, the object you want has the same index in the array/controller as it does in the table.

    So, it becomes simply a matter of calling:

    myObject=[fetchedArray objectAtIndex:tableRowIndex];
    

    or

    myObject=[myFetchedResultsController objectAtIndexPath:tableRowIndex];
    

    This is the real genius of the UITable. It always reflects the data model precisely. You never have to translate back and forth between the table indexes and your data model indexes.

提交回复
热议问题