如何提前提供填充的sqlite数据库
像我会有一个应用程序。使用已包含项目的数据库,而不仅仅是在第一次启动时下载数据我可以用正在使用的sqlite替换sqlite,但我不知道如何创建sqlite文件
-(void)importDatabaseToDocumentsDir
{
NSFileManager *fmngr = [[NSFileManager alloc] init];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Kalkulacka.sqlite" ofType:nil];
NSError *error;
if(filePath != nil && ![fmngr copyItemAtPath:filePath toPath:[NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),@"Kalkulacka.sqlite"] error:&error]) {
// handle the error
//NSLog(@"Error creating the database: %@", [error description]);
}
[fmngr release];
}
谢谢
答案 0 :(得分:1)
显而易见的方法是......
a)使用您的应用程序,创建所需数据并保存并复制生成的文件或
b)在Xcode项目中添加第二个“命令行工具”类型的目标,其中包含与数据模型相关的类,并允许您填充和保存填充的数据文件。