0

3 일 전 Twinstones라는 앱을 방금 출시했지만 지속적으로 업데이트했지만 이제는 핵심 데이터 모델 객체를 업데이트하려고합니다. . 사용자가 처음 앱을 열고 (기본적으로 매번) 매번 NSUserDefaults 개체를 사용하여 내 모델 개체의 초기 설정이 수행되었는지 여부를 확인합니다. 기본 객체의 값이 0이면 설정을 초기화하고, 1이면 설치를 무시합니다.기존 애플리케이션의 새로운 엔티티에 대한 핵심 데이터 마이그레이션 구현 방법 (필요한 경우)

분명히 초기 설정은 게임을 다운로드 한 70 명의 사람들 모두에게 완료되었습니다.

첫 번째 수준의 튜토리얼에 Entity를 추가하고 핵심 데이터를 사용하여 자습서를 본 적이 있는지 여부를 추적하고 싶습니다. 즉, 지금 구 모델 개체를이 개체로 마이그레이션해야합니다. 새로운 엔티티를 가진 새로운 것. 먼저 다른 NSUserDefault 개체 (초기 설정과 동일한 방식으로 적용)를 사용하여 첫 번째 수준에서 자습서를 실행할 것인지 여부를 결정해야합니까?

persistantStoreCoordinator 방법에서
- (NSManagedObjectContext *)managedObjectContext 
{ 
    if (_managedObjectContext != nil) { 
     return _managedObjectContext; 
    } 

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 
    if (coordinator != nil) { 
     _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; 
     [_managedObjectContext setPersistentStoreCoordinator:coordinator]; 
    } 
    return _managedObjectContext; 
} 

// from website 
- (NSManagedObjectModel *)managedObjectModel 
{ 
    if (_managedObjectModel != nil) { 
     return _managedObjectModel; 
    } 
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"ScoreModel" withExtension:@"momd"]; 
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 
    return _managedObjectModel; 
} 

// from website 
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    if (_persistentStoreCoordinator != nil) { 
     return _persistentStoreCoordinator; 
    } 
    NSURL *storeURL = [[self applicationDocumentsDirectory] 
        URLByAppendingPathComponent:@"Twinstones.sqlite"]; 
    NSError *error = nil; 
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
               configuration:nil 
                 URL:storeURL 
                options:nil 
                 error:&error]) { 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 
    return _persistentStoreCoordinator; 
} 

가 어떻게 마이그레이션을 구현하는 것이 :하지 않으면

, 여기에 내 관리되는 개체 컨텍스트에 대한 코드, 관리 개체 모델 및 영구 저장소 코디네이터? 기본 객체가 이미 초기화를 거쳤다는 사실을 감안할 때 다른 기본 객체를 추가하고 현재 모델 객체에 대한 참조를 가져온 다음 마이그레이션하고 새 객체를 추가해야 할 것 같았습니다.

코드에 실제로 들어가기 전에 실제로 이렇게 해본 적이 없습니다. (이 마이그레이션이 필요한 경우에도 마찬가지입니다.) 데이터를 저장하는 속성 목록이 절대로 우연히 악의적으로 변하지 않을 것이라는 보증이있는 다른 NSUserDefaults 개체를 사용할 수 있다면 그렇게 할 것입니다. 당신이 persistentStoreCoordinator에 저장소를 추가 할 때 구성 옵션의

NSDictionary* configuration = @{ 
         NSMigratePersistentStoresAutomaticallyOption : @YES, 
         NSInferMappingModelAutomaticallyOption:@YES 
         }; 

:

답변

0

는 다음과 같은 사전을 사용합니다.