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: Fri, 08 Apr 2011 08:17:12 -0400
On Apr 7, 2011, at 7:04 PM, Carter R. Harrison wrote:
>
> 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?
Well I ended up changing my store to a sqlite store and it started working right away. There are some options you can supply when creating the store to force the kernel to flush all changes to the store to disk in a synchronous manner which I applied the first time I tried. Apple's Documentation says this is comparatively much slower but I'm not working with large sets of data and the I don't need to save too frequently. I'm going to try backing off on some of these options to see if everything still works.
Nick - thanks so much for your help.
>> 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