views:

48

answers:

1

I am trying to use NSManagedObjectContext dependency injection as recommended by Marcus Zarra -- I'm creating an M.O.C. in my AppDelegate and passing it as a retained property to each of my view controllers.

Generally this seems to work well, but in a modal table view controller that presents data via an NSFetchedResultsController, I only see what was in the database when the app was launched. That is, if the user adds data at runtime, it gets added correctly to the database, but does not appear when the modal ViewController is opened and the NSFetchedResultsController is created (using the injected NSManagedObjectContext). However, if I close the app and restart, then open the modal view controller, I do see the data added in the previous session.

Do I have to refresh the M.O.C. in some way prior to creating the NSFetchedResultsController? I am absolutely sure that the modal view controller and the NSFetchedResultsController are being created, and the fetch is being executed, AFTER the new user data has been entered.

A: 

To start, you should log the moc in both app delegate and your view controller to confirm that the moc in both places has the same address and is therefore the same object.

If it is, then most likely you've got an issue with the FRC's cache. Set the cache to nil and/or refresh the cache and see if that resolves it.

TechZen
I logged the moc in both places and it is the same. The cache is already set to nil. So I'm still stumped...
ed94133
I had a stupid mistake in my save method. I removed it and all is fixed. Thank you for your answer anyway! If you think I should delete this question, let me know.
ed94133