I'm tearing my hair out trying to get this to work.
I've had a look at all the StackOverflow related problems but I just can't get the final step to work!
I have a NSFetchedResultsController
showing data from Core Data. This all works perfectly. When there is data in there it displays the data and everything is fine.
However, I have an asynchronous update that pulls down more data from an online server and saves it to Core Data.
What I am wanting to happen is that the NSFetchedResultsController
picks up these updates and then displays them (i.e. animates them onto the currently displayed tableView).
The set up I have at the moment is like so................
Thanks for both the responses to this, I have had another go at trying to get this to work but I'm still not seeing the update in "real-time".
I thought I'd have a go at explaining where I am with it now. I found a few problems with my initial set up which I have now fixed but still nothing.
OK, so first the classes and what happens where...
[Class = AppDelegate]
[Has managedObjectContext (main context) plus the persistent store etc...]
[Method = mergeChanges:notifiaction
this uses GCD to get back onto the mainThread and does mergeChangesWithObjectblahblah]
[Class = NetworkDataClass]
[This has its own ManagedObjectContext that gets created (in the main thread) upon init]
[Method = saveContext
1. Add AppDelegate as observer of didsavenotification of bgContext.
2. SaveContext.
3. Remove AppDelegate as observer] ( I know that the observation is working because I have a breakpoint in the AppDelegate that stops when it saves.)
[Method = getDataFromOnline (not actual name but you get the gist)
1. GCD onto bg thread.
2. Create an NSURLRequest.
3. Run the request synchronously.
4. Put the data into the class context.
5. Run self saveContext]
[Class = tableViewClass]
[Has the tableView and NSFetchedResultsController also uses NSFetchedResultsControllerDelegate]
[Method = viewWillAppear
1. run getDataFromOnline method in my network class singleton]
I have some default data in there to make sure it is being displayed and when I go into the tableViewClass (detailed above) I can see the data properly in the correct sort order with the correct section titles etc... so I can clear see that the fetchedresultscontroller is working.
I can also see (with breakpoints) that it triggers the getDataFromOnline method properly. I can see that data coming in and I can see it being added through my ManagedObject subclasses and this is all happening in the bgthread.
I can also see that when it saves the AppDelegate is running its mergeChanges function properly.
The only thing I can't see is the table being updated with the new data.
If I popToRootViewController and go back to my table then boom all the new data is there so I know that the merge has gone through and the new data has been added and merged but it just isn't appearing at merge time.
Is there something I'm missing?
Do I need to run reloadData on the table? Do I need to fire a "refetch" or something from the fetchedresultscontroller?
Really struggling with this now.
Thanks for any (more) help you can provide.