1

我有一个DB.swift文件可以使用 Core Data。在我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] CoreData: 错误:-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 options:(null) ...返回错误错误域=NSCocoaErrorDomain代码=134100“ (null)" UserInfo={元数据={ NSPersistenceFrameworkVersion = 640; NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }, reason=打开商店的模型和创建商店的模型不兼容} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 640; NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }; reason = "开店的型号和开店的型号不兼容"; 2015-11-13 17:14:09。435 MyTestApp[17121:1577592] 未解决的错误错误域 = NSCocoaErrorDomain 代码 = 134100 "(null)" UserInfo={metadata={ NSPersistenceFrameworkVersion = 640; NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }, reason=打开商店的模型和创建商店的模型不兼容}, [NSLocalizedDescription: 无法初始化应用程序保存的数据, NSLocalizedFailureReason: 创建或加载应用程序时出错' s 保存数据,NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={ NSPersistenceFrameworkVersion = 640; NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }, reason=开店的型号和开店的型号不兼容}] (lldb) NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }, reason=开店的型号和开店的型号不兼容}] (lldb) NSStoreModelVersionHashes = { 用户 = <3d1a75c4 8f710e63 26eb5f88 c4fe6477 b2af77a8 6f9d5600 6abaf2bc 2c6ba1da>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite;NSStoreUUID = "A979CF18-B316-4989-B118-A1CE44C0AAE8"; "_NSAutoVacuumLevel" = 2; }, reason=开店的型号和开店的型号不兼容}] (lldb) "_NSAutoVacuumLevel" = 2; }, reason=开店的型号和开店的型号不兼容}] (lldb) "_NSAutoVacuumLevel" = 2; }, reason=开店的型号和开店的型号不兼容}] (lldb)

4

0 回答 0