2009-10-08 2 views
3

코어 데이터를 사용하여 Mac에서 SQLite 파일을 만든 다음 내 iPhone 앱에 넣습니다 (호기심이 있다면 GitHub project). 업데이트 된 SQLite 파일로 앱 업데이트를 릴리스하고 싶습니다. 모델은 동일한 엔티티와 속성이 될 것이며 더 많은 데이터가있을 것입니다.코어 데이터 바꾸기

시뮬레이터에서 이전 sqlite 파일을 사용하여 앱을 실행합니다. 출구. sqlite 파일을 xcode의 새 파일로 바꿉니다. NSMigratePersistentStoresAutomaticallyOption 및 NSInferMappingModelAutomaticallyOption을 addPeristentStore 옵션에 추가하십시오. 그런 다음 앱을 다시 실행하면 앱에서 원본 파일의 데이터 만 표시합니다.

또한 Apple docs와 SO post에 따라 모델을 버전 관리하고 sqlite 파일의 이름을 변경하려고 시도했습니다. 그러나 여전히 운이 없다 (나는 모델이 여전히 동일하기 때문에 추측하고있다).

내가 어떻게 응용 프로그램을 최신 sqlite 파일을 읽을 수있는 아이디어?

답변

3

내 핵심 데이터 iPhone 응용 프로그램은 프로젝트가 생성되고 "저장 용 핵심 데이터 사용"이 선택된 경우 제공되는 표준 코드를 사용합니다.
내 파일 이름 상수 "DB_NAME"의 값을 변경하고 다시 빌드 할 때 사용되는 SQLite 데이터베이스를 전환합니다.

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent:DB_NAME]]; 

NSError *error = nil; 
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {