iosmanagedobjectcontext

More than one ManagedObjectContext


In my managedObjectModel I have several Entities. I think that it's possible to create ManagedObjectContext for each one... If it's true I would like to know:

  1. Do I need method - (NSManagedObjectModel *)managedObjectModel for each ManagedObjectContext?

  2. Do I need method - (void)saveContext for each ManagedObjectContext?


Solution

  • You don't need to do this. A single managed object context is designed to deal with multiple entities, and if there are relationships between your entities, they have to be in the same context.

    Separate contexts are useful for background threading and temporary workspaces, as explained rather well here. Until and unless you need that, stick with a single context.