Search code examples
ioscore-datansmanagedobjectcontext

Accessing the next object in managedObjectContext from my detailView


I have a simple application that uses Core Data / ManageObjectContext. It works very similar to Apple's sample app. The fetchedResultsController grabs the objects and builds out a table view. When I click it sends the Object at that index to the detail view. Simple.

What I want to do is access the next Object from my current detail view so that I need not return to the table view to move through to the next detail view.

I've seen some similar questions but the answers suggest creating a mutable array which seems to defeat the purpose of core data and managed objects.

Thanks!


Solution

  • Use NSFetchedResultsController

    /* Returns the fetched object at a given indexPath.
    */
    - (id)objectAtIndexPath:(NSIndexPath *)indexPath;
    

    Note:

    Creating a mutable array does not necessarily defeat Core Data nor NSManagedObjectContext, but it definitely would defeat the caching mechanism provided by NSFetchedResultsController.