1
votes

from the official RestKit page Restkit Github I found the following to reset the store:

- (void) resetSavedDatabase:(id)sender {
    RKManagedObjectStore *objectStore = [[RKObjectManager sharedManager] objectStore];
    [objectStore resetPersistentStores];
    [objectStore save:nil];    

}

That works. But if I then do the following after this method I got a error:

TestEntity *testEntity = [TestEntity createEntity];

testEntity.name = @"TestEntity";    

NSError *error;

[[RKObjectManager sharedManager].objectStore save:&error];

Error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'

Everything is called in the background. The idea is, that I want to preload some sqlite data and then synchronize them with my synchronize logic. (The logic is working when I do not delete the persistent store)

Can someone help me?

1
You deleted the store. Recreate it in the same way it is created on first run.Mundi
@Paul de Lange, I added the hyperlink.NDY
@Mundi, as I see in the RestKit code, deletePersistentStore creates automatically a new storeNDY
@Andy deletePersistentStore has changed to resetPersistentStores.. please update your question accordinglyabbood

1 Answers

1
votes

Yes it will automatically recreate the store, but in the following step it will also recreate an object context.

So you almost definitely want to do this on the main thread. Otherwise, RestKit will associate the created persistent store with an object context in the background thread and that will disappear when the thread ends.

I completely don't understand why you want to do this though.