1
votes

Bit of a newb here, with a general question about architecture.

I have an iOS app with two separate views both talking to the same core data model.

I have implemented an NSFetchedResultsController for one of the views, as a local property. Lots of delegate methods to implement...

  • (void)controllerWillChangeContent:(NSFetchedResultsController *)controller

  • (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id )sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type

  • (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath

  • (void)controllerDidChangeContent:(NSFetchedResultsController *)controller

  • (NSFetchedResultsController *)fetchedResultsController

...most of which are boilerplate, but I'd like to avoid just copy/pasting these into the other view.

Any suggestions on rearchitecting to avoid such heresy...?

1

1 Answers

0
votes

First of all, I hope you mean "view controllers" when you mention views. Putting this code into a UIView subclass would be extremely bad design. It's controller code, so don't put it in a view.

As for limiting duplication, you're using an object oriented language, so one possibility is to make both of these view controllers inherit from a common parent class. Move the duplicate code into the parent, and have each view controller call super's implementation before doing whatever their own implementation requires. That will probably require some care to make sure that the superclass's implementation is generic enough for both of its subclasses. If that proves extremely difficult, it might be that the code isn't generic enough for refactoring to help.