다른 사람이이 문제를 발견했는지 궁금합니다.coredata가 xcode 4.3에서 작동하지 않습니까?
나는 이전 xcode 버전에서 훌륭하게 작동했던이 코드 조각을 가지고 있습니다.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"mydb.sqlite"];
/*
Set up the store.
For the sake of illustration, provide a pre-populated default store.
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"mydb" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
[self addSkipBackupAttributeToItemAtURL:storeUrl];
NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
Typical reasons for an error here include:
* The persistent store is not accessible
* The schema for the persistent store is incompatible with current managed object model
Check the error message to determine what the actual problem was.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
는 나는이에서 다음과 같은 기대 :
- 빈 "MYDB는"처음부터 만들 수 내 번들에 더 "mydb.sqlite"가없는 경우.
- 내 기본 번들에 "mydb.sqlite"가 있으면 지정된 디렉토리에 복사 될 것으로 기대됩니다.
- "mydb.sqlite"가 내 xcdatamodel과 호환되지 않으면 앱이 중단되어야합니다.
그러나 이전에 이미 생성 된 db에서만 작동합니다. 예를 들어 "mydb.sqlite"라는 임의의 db를 내 번들에 넣고 원래의 파일을 삭제하려고하면
응용 프로그램이 다운되지 않습니다! 빈 db가 작성되고 새 db가 무시됩니다. 이것은 내 코드를 위반하는 것처럼 완전히 잘못되었습니다.
또한 원래 데이터베이스를 다시 추가하면 아무 일도 발생하지 않으며 응용 프로그램은 빈 db를 만듭니다.
(그래 나는 시뮬레이션 응용 프로그램을 삭제, 내 프로젝트를 청소하고, 변경이 발생하기 전에, 심지어 빌드 폴더를 삭제합니까!)
어떤 아이디어가?
무엇이 오류입니까? 그것을 게시 할 수 있습니까? – Raptor
오류가 없습니다. 그것은 단지 내 코드에 따라야하는 방식으로 작동하지 않는 관찰이다 –