Search code examples
ioscocoa-touchcore-datansfetchedresultscontroller

Complex fetch-request for NSFetchedResultsController


Here's a simplified look for my model:

  • Media has property 'status' that can be either 'Uploading' or 'Uploaded'.
  • User has property 'syncStatus' that be either 'NotSynced' or 'Synced'.
  • ObjectX is a 'linking' object between User and Media
  • User has to-many relationship to ObjectX
  • ObjectX has to-one relationship to Media

Is there any way to use NSFetchedResultsController to fetch all Users that are 'Synced' and whose all media are 'Uploaded'? It would have to update its content also when 'Media' status is changed so that new User should be fetched. I've heard NSFetchedResultsController doesn't work well with such complex fetch requests.

Model Graph


Solution

  • It would be more practical to model the fetch by denormalizing the data. You can add a 'status' Boolean to User indicating whether all their Media is uploaded.

    This would be much more efficient than having to aggregate the status of each object's model.