Search code examples
iosobjective-cnsfetchedresultscontroller

ios/objective-c: changeUpdate and configureCell vs cellForRowAtIndexPath with NSFRC


For a tableviewcontroller I use cellforrowatindexpath to configure the cell.

However, when changing something in core data, the delegate method controllerDidChangeObjectatObjectAtIndexPath fires and for the case changeUpdate, Apple seems to require that you rewrite the row with configureCell.

Is it best practice/necessary to entirely duplicate the code for cellforRowAtIndexPath in configureCell or is there a better way to keep the code identical. For example, would there be a way to do away with one or the other code blocks.

It seems error prone and redundant to have to have the same code for configuring the cell in both cellforrowatindexpath and configure cell.


Solution

  • Put the common code in another method and then call this new method from cellForRowAtIndexPath and configureCell. Or simply call configureCell from cellForRowAtIndexPath if appropriate.

    Do not duplicate code. Refactor common code into a method that can be called from the places you would have had the duplicate code.