views:

302

answers:

1

I'm having trouble getting my UI to reflect external changes (made by another process) to an sqlite data store.

I have a fairly standard core data based NSArrayController / table view. My app gets notified that external changes have been made to the data, at which point I do a

[managedObjectContext reset]; // brute force, but data set is small

The problem is, doing this clears all data from the table. The array controller's arrangedObjects is also empty. I thought a subsequent

[arrayController fetch:nil];

might help, but it doesn't. Executing a fetch request on the managedObjectContext shows the data is present and updated, so the managedObjectContext knows about the changes.

Any clues as to how to "recover" from the reset? Or perhaps the reset approach is wrong altogether, in which case is there a better way to load the external changes?

+2  A: 

I don't think two processes are supposed to work in the same Core Data database. It is probably better to let one process act as a server that owns (and opens) the database and let the other send it commands to make changes. I don't think Core Data was ever meant to support multiple processes talking to the same db.

St3fan
That's correct. Core Data manages atomic stores and cannot be used like a client-server database.
Rob Keniger
Yes, now that I've refactored to have the same process - and in fact the same thread - always operating on the database, things are working well.A pity though, seeing as the underlying Sqlite database handles multi-process access and manipulation. It seems reasonable to expect Core Data to be able to update afresh from the database when notified to do so.
Adrian