просто интересно, сталкивался ли кто-то еще с этим.
Я получил этот кусок кода, который работал блестяще в предыдущих версиях 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, приложение должно аварийно завершить работу.
однако это работает только с уже созданными ранее БД.Если, например, я попытаюсь поместить случайную базу данных с именем «mydb.sqlite» в свой комплект и удалить исходную, то
приложение не падает !!!создается пустой БД, а новый БД игнорируется.Это совершенно неверно, так как это противоречит моему коду.
Кроме того, если я добавляю исходную базу данных, ничего не происходит, и приложение просто создает пустую базу данных.
(и да, я действительно чищупроект, удалите приложение sim и даже удалите папку сборки до того, как произойдут какие-либо изменения!)
любые идеи ??