RE: How to synchronize two managedObjectContexts...
RE: How to synchronize two managedObjectContexts...
- Subject: RE: How to synchronize two managedObjectContexts...
- From: "Jon C. Munson II" <email@hidden>
- Date: Thu, 2 Apr 2009 08:55:48 -0400
- Organization: JTA Enterprises LLC
Namaste!
OK, after spending gobs of time (and some sleep) on this, I solved my issue.
In my NSWindowController subclass's .m file I added in the filename
processing routine (which is readFromPasteBoard which is called from
performDrop):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(mergeChangesFromContextSaveNotification)
name:NSManagedObjectContextDidSaveNotification object:moc]; // moc is the
secondary moc used to add the dropped filenames
Then, in the selector implementation:
- (void)mergeChangesFromContextSaveNotification:(NSNotification
*)notification
{
[[NSApp delegate] managedObjectContext]
mergeChangesFromContextDidSaveNotification:notification];
}
My misunderstanding yesterday was not interpreting the documentation
correctly on what to do with mergeChangesFromContextDidSaveNotification.
Works like a charm now! :)
Peace, Love, and Light,
/s/ Jon C. Munson II
> -----Original Message-----
> From: cocoa-dev-bounces+jmunson=email@hidden [mailto:cocoa-dev-
> bounces+jmunson=email@hidden] On Behalf Of Jon C. Munson II
> Sent: Wednesday, April 01, 2009 4:29 PM
> To: 'Cocoa Developers'
> Subject: How to synchronize two managedObjectContexts...
>
> Namaste!
>
> I'm having trouble with an implementation of drag-and-drop for a
> core-data-based application.
>
> Scenario: I'm implementing the drag destination for file names coming
> from
> an application (like Finder). The receiving window will take the
> filenames
> and create the appropriate records for the core-data entity that is the
> basis of the window.
>
> The drop isn't so much the issue, but rather what to do with it.
>
> If there is a better way to do this, I'd appreciate hearing about it.
>
> After trying:
>
> 1. Adding to the array controller for that entity,
> 2. Adding to the main managedObjectContext,
> 3. Adding to a distinct managedObjectContext,
>
> And finding that 1 & 2 weren't workable (didn't go too far with #1 as the
> add method didn't do what I wanted, and #2 wouldn't create the default
> data
> as stipulated by the class file for the entity and did a great deal of
> hangtime), #3 works just fine (no crashes, and default data populates as
> expected) EXCEPT I can't seem to get the secondary MOC to notify the
> primary
> MOC of the additions.
>
> I've seen the dox for -mergeChangesFromContextDidSaveNotification (and
> then
> the refreshObject to follow), however, I could not find a complete example
> of its implementation (where does that go, etc.).
>
> So, I'm not sure where to go with this - I could use a good example or
> better explanation.
>
> Many thanks in advance!
>
> Peace, Love, and Light,
>
> /s/ Jon C. Munson II
>
>
> _______________________________________________
>
> 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