Re: Managed Objects and Contexts
Re: Managed Objects and Contexts
- Subject: Re: Managed Objects and Contexts
- From: John Pannell <email@hidden>
- Date: Wed, 30 May 2012 17:02:33 -0600
Hi Richard-
The reasons to have multiple contexts within an app are as varied as application architectures, and do not need to correspond to multiple users (I'd go so far as to say "shouldn't", but I'm sure someone could find a way to make it work). An app I once wrote maintained two contexts that looked at the same data. The first context was essentially user-facing: actions taken in the UI resulted in changes in the context. The second context was something of a read-only snapshot of the first that was then used on a background thread to do work (the app allowed the user to visually create a workflow to do this work).
In more modern Core Data usage, it is good practice to maintain two contexts: a parent and a child context will allow for background saving in the new document architecture "for free".
In short, there are possible scenarios for using multiple contexts that are views on the same data, but the one you mention (a context for each user independently manipulating the same data) is probably not one of them.
Hope this helps!
John
On May 30, 2012, at 4:45 PM, Richard Somers wrote:
> I have a question about multiple contexts.
>
> First a quote from the Core Data Programming Guide - "To consider this from a different perspective, a given object in a persistent store may be edited in more than one context simultaneously. Each context, however, has its own managed object that corresponds to the source object, and each managed object may be edited independently. This can lead to inconsistencies during a save-Core Data provides a number of ways to deal with this."
>
> So to recap, a given object in a persistent store may be edited in multiple contexts simultaneously and each context has its own managed object corresponding to the given source object. And when the user saves everything is sorted out by Core Data.
>
> I know that Core Data is not multi-user but this sounds like a multi-user data base use case scenario. Multiple contexts (users) all potentially looking at the same data and the first one to save wins.
>
> Why did Apple do this? What would be a legitimate use case for this scenario?
>
> --Richard
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden