iphone - 替换应用程序中的核心数据 SQLite 文件

标签 iphone sqlite core-data

我正在 Mac 上使用 Core Data 创建一个 SQLite 文件,然后将其放入我的 iPhone 应用程序中(GitHub project 如果好奇的话)。我想使用更新的 SQLite 文件发布应用程序更新。该模型将具有相同的实体和属性,只是会有更多的数据。

我使用旧的 sqlite 文件在模拟器中运行该应用程序。导出。在 xcode 中将 sqlite 文件替换为新文件。将 NSMigratePeristentStoresAutomaticallyOption 和 NSInferMappingModelAutomaticallyOption 添加到 addPeristentStore 选项。然后再次运行应用程序,但应用程序仅显示原始文件中的相同数据。

我还尝试根据 Apple 文档和此 SO post 对模型进行版本控制并重命名 sqlite 文件。但仍然没有运气(我猜是因为模型仍然相同?)。

关于如何让应用程序读取较新的 sqlite 文件有什么想法吗?

最佳答案

我的 Core Data iPhone 应用程序使用创建项目并选择“使用 Core Data 进行存储”时提供的标准代码。
当我更改文件名常量“DB_NAME”的值并重建时,它将切换使用的 SQLite 数据库:

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent:DB_NAME]];

NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {

关于iphone - 替换应用程序中的核心数据 SQLite 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1535321/

相关文章:

iphone - 如何摆脱 UIWebView 中嵌入的 youtube 视频周围的白色边框?

iphone - iOS 5 - Coredata Sqlite DB 在杀死应用程序后丢失数据

ios - 在 TableView 上添加 SearchBar

ios - Swift:数据库更新后 View Controller 崩溃

ios - 为什么 Json 字典总是在 nsdata(Bytes) 中给出响应。我怎样才能从网络服务中获取字典

iPhone iOS 如何显示应用程序中存储的照片的幻灯片?

iphone - iPhone应用程序在Apple Store上载

SQL:计算两个不同条目具有的值的数量

Sqlite 创建唯一的一对列

sqlite - 不将 SQLite DB 放在 NFS 上的 createrepo 解决方法?