简体   繁体   English

RestKit重置核心数据存储

[英]RestKit Reset Core Data Store

from the official RestKit page Restkit Github I found the following to reset the store: 从官方的RestKit页面Restkit Github中,我发现以下内容可重置商店:

- (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' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“无法从此NSManagedObjectContext的协调器访问对象的持久性存储”

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. 我的想法是,我想预加载一些sqlite数据,然后将它们与我的同步逻辑进行同步。 (The logic is working when I do not delete the persistent store) (当我不删除持久性存储时,逻辑起作用)

Can someone help me? 有人能帮我吗?

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. 否则,RestKit将在后台线程中将创建的持久性存储与对象上下文相关联,并且在线程结束时将消失。

I completely don't understand why you want to do this though. 我完全不明白您为什么要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM