0
我正在使用coredata在我的第一个应用程序。一切都很完美。当我在我的设备上调试应用程序(没有它已经安装在设备上)时,然后退出应用程序,手动修改sqlite dbase然后再次调试应用程序,它似乎使用旧版本的数据库。如果两个sqlite文件具有相同的名称,是否有办法告诉它只是替换那里?CoreData更新的SQLite数据库
下面是我的代码片段:
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"mydata.sqlite"];
/*
Set up the store.
For the sake of illustration, provide a pre-populated default store.
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSLog(@"copying default from sqlite");
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"mydata" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
正如你可以看到,如果没有最初找到数据库从应用程序加载sqlite的文件。除了更改sqlite文件的名称或使用设置,有没有办法说如果你有什么可以刷新你所拥有的,并从头开始?
我担心用户购买应用程序,然后当我发布更新时,他们仍然看到来自旧版数据库的数据。
感谢, 豪伊
“......有没有办法说清楚你有什么需要刷新的东西,然后从头开始?”如果这个商店是只读的,用户必须为他们自己创建一个空白的自己的数据,那没问题。否则,这是一个非常糟糕的主意。 – 2010-03-02 10:29:02