Pregunta

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?

¿Fue útil?

Solución

if you have twice .sqlite3 in your project

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top