Search code examples
iosobjective-cmultithreadingcore-datansmanagedobjectcontext

CoreData MultiThreading Delete


In my iPad application, I am using Multithreading to read data from my database and hence I am using different manged object contexts as explained Fred McCann's blog

The problem I am facing is while deleting items from the database. When I try to delete, I get the error that the managedObjectContext cannot delete another objectContext's data. How do I solve this problem?

It would be great is someone could help me out with this.


Solution

  • You need to pass the objectIds around and then get that object from the other context.

    NSManagedObject *object = // get the object...
    NSManagedObjectID *objectID = object.objectID;
    // Pass to other context on other thread...
    // ...
    NSManagedObject *sameObjectDifferentContext = [managedObjectContext objectWithID:objectID]