2012-09-10 4 views
4

모든 앱 업데이트마다 전체 핵심 데이터 데이터베이스를 완전히 지운 다음 다시 설정하고 싶습니다. 나는 그렇게하지 못했다. 나는 여러 가지를 시도했다. 이것은 내가 가장 가까이있는 것 같다. 여러 게시물을 찾았지만 솔루션 중 아무 것도 내 용도로 사용되지 않았습니다.MagicalRecord : 전체 데이터를 제거하고 코어 데이터 스택을 다시 설정하십시오.

저는 다양한 객체를 얻기위한 몇 가지 간단한 방법을 제공하는 MagicalRecord을 사용하고 있습니다. 당신은 영구 저장소 SQLite는 DB를 삭제하려면이 호출에서 URL을 사용할 수 있습니다

+ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName; 

:

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]; 

답변

4

당신이 영구 저장소의 URL을 얻을 수있는 NSPersistentStore+MagicalRecord 카테고리가 : 여기에 내 코드입니다 NSFileManager를 사용합니다.

관련 문제