如果尚未创建数据库,我有一段代码可以添加数据库。这是代码
-(void) checkAndCreateDatabase{
// Check if the SQL database has already been saved to the users phone, if not then copy it over
NSString *path=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *database_path=[path stringByAppendingPathComponent:@"Favorite_Database.sqlite"];
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
// Check if the database has already been created in the users filesystem
BOOL success = [[NSFileManager defaultManager] fileExistsAtPath:database_path];
// If the database already exists then return without doing anything
if(success) {
//[fileManager removeFileAtPath:databasePath handler:nil];
return;
}
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Favorite_Database.sqlite"];
// Copy the database from the package to the users filesystem
[[NSFileManager defaultManager] copyItemAtPath:databasePathFromApp toPath:database_path error:nil];
}
当它到达这条线BOOL success = [[NSFileManager defaultManager] fileExistsAtPath:database_path];
时,它只是跳过,其余的继续前进。我没有进入 if 语句。我需要它来检查,所以我可以添加这个数据库
我怎样才能让它正常工作?