Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MagicalRecord:删除整个数据并再次设置核心数据堆栈_Ios_Core Data_Magicalrecord - Fatal编程技术网

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