Ios Swift 2.0-CoreData:错误:-addPersistentStoreWithType:SQLite配置:(null)
我有一个Ios Swift 2.0-CoreData:错误:-addPersistentStoreWithType:SQLite配置:(null),ios,swift,api,core-data,swift2.1,Ios,Swift,Api,Core Data,Swift2.1,我有一个DB.swift文件以使用核心数据。在我的persistentStoreCoordinator中的abort()行中,我收到了我在下面写的错误 这就是我的代码的外观: lazy var managedObjectModel: NSManagedObjectModel = { let modelURL = NSBundle.mainBundle().URLForResource("MyAppData", withExtension: "momd")! return
DB.swift
文件以使用核心数据。在我的persistentStoreCoordinator
中的abort()
行中,我收到了我在下面写的错误
这就是我的代码的外观:
lazy var managedObjectModel: NSManagedObjectModel = {
let modelURL = NSBundle.mainBundle().URLForResource("MyAppData", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("coredata.sqlite")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
do {
try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch {
coordinator = nil
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error as NSError
let wrapperError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// 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), \(wrapperError.userInfo)")
abort() // ~ Here I am receiving error ~
}
return coordinator
}()
`2015-11-13 17:14:09.432 MyTestApp[17121:1577592]核心数据:错误:-addPersistentStoreWithType:SQLite配置:(null)URL:file:///Users/sentiasa/Library/Developer/CoreSimulator/Devices/3E42AB50-BBB1-4190-93E1-2EFF77FCA7CB/data/Containers/Data/Application/F4E05308-852A-42E0-AB5A-8712CD6FD508/Documents/coredata.sqlite 选项:(空)。。。返回的错误域=NSCOCAERRORDOMAIN Code=134100“(null)”UserInfo={metadata={
NSPersistenceFrameworkVersion=640;
NSStoreModelVersionHashes={
用户=;
};
NSStoreModelVersionHashesVersion=3;
NSStoreModelVersionIdentifiers=(
""
);
NSStoreType=SQLite;
NSStoreUUID=“A979CF18-B316-4989-B118-A1CE44C0AAE8”;
“_NSAutoVacuumLevel”=2;
},reason=用于打开存储的模型与用于创建存储的模型}与userInfo dictionary不兼容{
元数据={
NSPersistenceFrameworkVersion=640;
NSStoreModelVersionHashes={
用户=;
};
NSStoreModelVersionHashesVersion=3;
NSStoreModelVersionIdentifiers=(
""
);
NSStoreType=SQLite;
NSStoreUUID=“A979CF18-B316-4989-B118-A1CE44C0AAE8”;
“_NSAutoVacuumLevel”=2;
};
原因=“用于打开存储的模型与用于创建存储的模型不兼容”;
}
2015-11-13 17:14:09.435 MyTestApp[17121:1577592]未解决的错误域=NSCOCAERRORDOMAIN代码=134100“(null)”用户信息={metadata={
NSPersistenceFrameworkVersion=640;
NSStoreModelVersionHashes={
用户=;
};
NSStoreModelVersionHashesVersion=3;
NSStoreModelVersionIdentifiers=(
""
);
NSStoreType=SQLite;
NSStoreUUID=“A979CF18-B316-4989-B118-A1CE44C0AAE8”;
“_NSAutoVacuumLevel”=2;
},原因=用于打开存储的模型与用于创建存储的模型不兼容},[NSLocalizedDescription:未能初始化应用程序保存的数据,NSLocalizedFailureReason:创建或加载应用程序保存的数据时出错,NSUnderlyingError:error Domain=NSCOCAerorDomain Code=134100”(null)UserInfo={元数据={
NSPersistenceFrameworkVersion=640;
NSStoreModelVersionHashes={
用户=;
};
NSStoreModelVersionHashesVersion=3;
NSStoreModelVersionIdentifiers=(
""
);
NSStoreType=SQLite;
NSStoreUUID=“A979CF18-B316-4989-B118-A1CE44C0AAE8”;
“_NSAutoVacuumLevel”=2;
},reason=用于打开存储的模型与用于创建存储的模型不兼容}]
(lldb)
错误消息非常明确地说明了原因:“reason=用于打开存储的模型与用于创建存储的模型不兼容”,因此您的模型在创建原始存储后发生了更改。您应该移除存储并用新的存储替换它(如果只是在开发中),或者您应该采用迁移策略。重置模拟器解决了问题,干杯!错误消息非常明确地说明了原因:“reason=用于打开存储的模型与用于创建存储的模型不兼容”,因此您的模型在创建原始存储后发生了更改。您应该移除存储并用新的存储替换它(如果只是在开发中),或者您应该采用迁移策略。重置模拟器解决了问题,干杯!