目前我正在使用.xcdatamodel将预先存在的sqlite文件和核心数据模型导入到新创建的Swift应用程序中。它有两张表A& B.每当我尝试访问A表行时。它给了我以下错误。
"用于打开商店的模型与用于创建商店的模型不兼容"
当我搜索此错误时,我发现了一些我应用但无效的解决方案。已经应用的解决方案是:
这是我的代码:
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url : NSURL! = NSBundle.mainBundle().URLForResource("db", withExtension: "sqlite")
println("Url :: \(url)")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
var options = NSMutableDictionary()
options[NSReadOnlyPersistentStoreOption] = true
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options, error: &error) == nil {
coordinator = nil
// Report any error we got.
let dict = NSMutableDictionary()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError.errorWithDomain("YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
有人可以帮我解决这个问题。感谢。