Re: Two Applications Sharing Same Core Data Database
Re: Two Applications Sharing Same Core Data Database
- Subject: Re: Two Applications Sharing Same Core Data Database
- From: "Carter R. Harrison" <email@hidden>
- Date: Thu, 07 Apr 2011 19:04:20 -0400
On Apr 7, 2011, at 6:38 PM, Nick Zitzmann wrote:
>
> On Apr 7, 2011, at 4:24 PM, Carter R. Harrison wrote:
>
>> I really appreciate all of your help. I gave your suggestion a shot and I've run into problems. Here's what happens.
>>
>> 1. I create a new NSManagedObject in my main application. It gets inserted into the context.
>> 2. I save the context. I can see the persistent store update in a text editor (its an XML store).
>> 3. I send a distributed notification with the NSManagedObject's ObjectID.
>> 4. My background application consumes the notification and uses the object ID to get an NSManagedObject (using [NSManagedObjectContext objectWithID:]. This produces an NSManagedObject that is a fault.
>> 5. I try to fire the fault by using [NSManagedObject valueForKey:].
>> 6. Step 5 results in an exception "CoreData could not fulfill a fault for '0x1001029e0 <x-coredata://BB194166-B2FB-48ED-8177-E66F95B6CA3A/Alert/p118>'"
>>
>> I'm not sure I understand why this is happening. If the object is truly a fault then shouldn't Core Data go back to the persistent store to find the object?
>
> I think I've seen this before... Try calling sync() at the top of your notification handler. That will force external database changes to be written to disk.
>
> If that doesn't work, then you may need to fetch the object from the context using some identifier other than the object ID. We do this in our products that share a database, and it works for us when a helper app receives a notification from the master app that a record has been added/updated/deleted.
>
Well no dice with either option. sync() doesn't do it and a fetch request using a different identifier yields 0 objects. Do your products use XML stores?
> Nick Zitzmann
> <http://www.chronosnet.com/>
>
_______________________________________________
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