Ios MagicalRecord:删除整个数据并再次设置核心数据堆栈
对于每一次应用程序更新,我都希望彻底擦除我的整个核心数据数据库,然后重新设置它。我没有成功地这样做。我尝试过各种各样的事情,这似乎是我最近的一次尝试。我发现了几个这样的帖子,但没有一个解决方案符合我的目的 我使用的是Ios MagicalRecord:删除整个数据并再次设置核心数据堆栈,ios,core-data,magicalrecord,Ios,Core Data,Magicalrecord,对于每一次应用程序更新,我都希望彻底擦除我的整个核心数据数据库,然后重新设置它。我没有成功地这样做。我尝试过各种各样的事情,这似乎是我最近的一次尝试。我发现了几个这样的帖子,但没有一个解决方案符合我的目的 我使用的是MagicalRecord,它提供了几种获取各种对象的快捷方法。这是我的密码: if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"buildVersion"] intValue] < [[[[NSBundle
MagicalRecord
,它提供了几种获取各种对象的快捷方法。这是我的密码:
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"buildVersion"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]) {
NSPersistentStore *store = [NSPersistentStore defaultPersistentStore];
NSError *error;
NSURL *storeURL = [NSPersistentStore defaultLocalStoreUrl];
NSPersistentStoreCoordinator *storeCoordinator = [NSPersistentStoreCoordinator defaultStoreCoordinator];
[storeCoordinator removePersistentStore:store error:&error];
[[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error];
[[NSUserDefaults standardUserDefaults] setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"buildVersion"];
}
[MagicalRecord setupCoreDataStack];
if([[[NSUserDefaults standardUserDefaults]objectForKey:@“buildVersion”]intValue]<[[[NSBundle mainBundle]infoDictionary]objectForKey:@“CbundLeverVersion”]intValue]){
NSPersistentStore*store=[NSPersistentStore defaultPersistentStore];
n错误*错误;
NSURL*storeURL=[NSPersistentStoreDefaultLocalStoreUrl];
NSPersistentStoreCoordinator*storeCoordinator=[NSPersistentStoreCoordinator defaultStoreCoordinator];
[storeCoordinator removePersistentStore:存储错误:&错误];
[[NSFileManager defaultManager]removeItemAtPath:storeURL.path错误:&错误];
[[NSUserDefaults standardUserDefaults]设置对象:[[NSBundle mainBundle]信息字典]objectForKey:@“CbundLeverVersion”]forKey:@“buildVersion”];
}
[MagicalRecord setupCoreDataStack];
有一个NSPersistentStore+MagicalRecord
类别,允许您获取持久存储的URL:
+ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName;
您可以使用此调用中的URL,使用NSFileManager删除持久存储SQLite db