Вопрос

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"idataBase.sqlite3"];
NSLog(@"%@",databasePath);
NSString *databasePathFromApp = [[NSBundle mainBundle] pathForResource:@"idataBase" ofType:@"sqlite3"];
NSLog(@"%@",databasePathFromApp);
bool databaseAlreadyExists = [[NSFileManager defaultManager] fileExistsAtPath:databasePath];
if (!databaseAlreadyExists){
    [[NSFileManager defaultManager] copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}

I tried to copy the database to document directory, But it returns null when i try to get the database path from main bundle and my app crashed. The database is present in app. But why it returns null?

Это было полезно?

Решение

if you have twice .sqlite3 in your project

because may be your xCode target is "Build Phases" add the file under "Copy Bundle Resources"".

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top