У меня есть приложение, в котором я пытаюсь сохранить несколько разных таблиц в каталогах документов.Первый сохраняет нормально, а другие нет.Я исследовал и не нашел ничего, что говорит, что я не могу этого сделать.Надеюсь, кто-то может пролить свет.Код, который я использую, является типичным «CreateEditableCopyOfDatabaseIfNeeded», но, как я уже сказал, у меня есть несколько версий в зависимости от того, какую БД я пытаюсь сохранитьПриведенный ниже код является вторым, который не работает с «невозможностью открыть БД». Заранее спасибо.
- (void)createEditableCopyOfScheduleDatabaseIfNeeded
{
//test if DB already exist
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//save new DB's
NSString *writableScheduleDBPath = [documentsDirectory stringByAppendingPathComponent:@"schedulelist.sqlite3"];
NSLog(@"writable Schedule path:%@", writableScheduleDBPath);
success = [fileManager fileExistsAtPath:writableScheduleDBPath];
if (!success)
NSLog(@"Failure to open Schedule DB");
if (success) return;
//the writable database does not exist, so copy the default to the appropriate location
NSString *defaultScheduleDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"schedulelist.sqlite3"];
NSLog(@"default Schedule path:%@", defaultScheduleDBPath);
success = [fileManager copyItemAtPath:defaultScheduleDBPath toPath:writableScheduleDBPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create Schedule writable database:%@", [error localizedDescription]);
}