NSFetchedResultsController and NSOperation

In the UITableViewController I am using NSFetchedResultsController for my data. Everything works fine, except when I start importing some objects into a separate stream: I use NSOperationQueue , in which I insert objects into my ManagedObjectContext . This happens in a separate view. NSFetchedResultsController doesn't look like this and writes to the console:

Serious application error. An exception was detected by the NSFetchedResultsController delegate during the call to -controllerDidChangeContent :. Try to create two animations for a cell with userInfo (null)

Apparently, he is trying to extract new objects.

In the concurrency section , the Master Data Programming Guide says something like using a ManagedObjectContext for each thread, but that sounds pretty complicated.

Now I do not know if I should create my own subclass of NSOperation by creating ManagedObjectContext , etc. in it, or is it possible to prevent the NSFetchedResultsController from being updated for some time?

I would be grateful for the help, Fabian

+4
source share
1 answer

You need NSManagedObjectContext per stream, sorry!

This is not just an NSFetchesResultsController that will access your context - coreData will not receive some data until you have access to your context in your context.

However, this is only the context that needs to be created for each thread. Just write a method for your delegate that creates the context of the managed entity and calls it in each of your NSOperations - this will make them for the stream, and not for everyone, using the same one.

A managed context in the main thread can also be created using this method.

+4
source

All Articles