我是iOS开发新手,我在使用Sqlite的应用程序中进行更改。我在一些表添加了一些新的领域,我浏览数据库软件和 增加了新的领域inventory_db_src.sqlite但是当我在模拟器看到它使用inventory_db.sqlite这是奇怪的,因为没有inventory_db。解决方案中的sqlite文件,以及通过SQL脚本创建数据库的代码。如果我调试代码,它得到inventory_db.sqlite路径成功,从来没有执行inventory_db_src.sqlite线,并把inventory_db.sqlite在模拟器在我的新领域不存在,因为我在inventory_db_src.sqlite把这些。请帮我ios:将Sqlite文件放入解决方案的位置?
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"inventory_db.sqlite"];
// [fileManager removeItemAtPath:dbPath error:nil];
success = [fileManager fileExistsAtPath:dbPath];
success = NO;
if (success) {
int savedVersion = [[NSUserDefaults standardUserDefaults] integerForKey:kVERSION_KEY];
if (kCURRENT_DB_VERSION != savedVersion) {
[fileManager removeItemAtPath:dbPath error:nil];
success = NO;
}
}
if (!success) {
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"inventory_db_src.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
_INVENTORY_DB = [[FMDatabase alloc] initWithPath:dbPath];