我的核心数据在我的应用中运行.因此,我获取XML文件,将数据解析为模型对象并将其插入到核心数据中.它们保存在持久性存储中,我可以在重新启动应用程序时访问它们.但是,我希望能够随意刷新持久存储中的数据,因此我需要先从存储中删除现有对象.对此有直接的方法吗?
谢谢
我找到了这个解决方案
[managedObjectContext lock];
[managedObjectContext reset];//to drop pending changes
if ([persistentStoreCoordinator removePersistentStore:persistentStore error:&error])
{
NSURL* storeURL = [NSURL fileURLWithPath:[self pathForPersistentStore]];
[[NSFileManager defaultManager] removeFileAtPath:[storeURL path] handler:nil];
[self addPersistentStore];//recreates the persistent store
}
[managedObjectContext unlock];
Run Code Online (Sandbox Code Playgroud)