swift 3中的核心数据轻量级迁移不起作用

swift 3中的核心数据轻量级迁移不起作用,swift,core-data,swift3,Swift,Core Data,Swift3,我正在使用persistentContainer lazy var persistentContainer: NSPersistentContainer = { /* The persistent container for the application. This implementation creates and returns a container, having loaded the store for the

我正在使用persistentContainer

lazy var persistentContainer: NSPersistentContainer = {
        /*
         The persistent container for the application. This implementation
         creates and returns a container, having loaded the store for the
         application to it. This property is optional since there are legitimate
         error conditions that could cause the creation of the store to fail.
         */
     //   let container = NSPersistentContainer(name:"YiuPai")


       let container = NSPersistentContainer(name:"YiuPai")

        let storeUrl = self.applicationDocumentsDirectory.appendingPathComponent("YiuPai.sqlite")

        print(storeUrl)


        let description = NSPersistentStoreDescription(url: storeUrl)

        description.shouldInferMappingModelAutomatically = true
        description.shouldMigrateStoreAutomatically = true

        container.persistentStoreDescriptions = [NSPersistentStoreDescription(url: storeUrl)]


        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() 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.

                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()
错误我正在

2017-08-24 16:37:43.912800+0530 YiuPai[1688:496051] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/YiuPai.sqlite options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/YiuPai.sqlite, reason=Can't copy source store to destination store path, destinationURL=file:///var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/.YiuPai.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170851460 {Error Domain=NSSQLiteErrorDomain Code=5 "(null)" UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/.YiuPai.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, Source database Path=/var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/YiuPai.sqlite, reason=Failed to replace destination database}}} with userInfo dictionary {
    NSUnderlyingError = "Error Domain=NSSQLiteErrorDomain Code=5 \"(null)\" UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/.YiuPai.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, Source database Path=/var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/YiuPai.sqlite, reason=Failed to replace destination database}";
    destinationURL = "file:///var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/.YiuPai.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3";
    reason = "Can't copy source store to destination store path";
    sourceURL = "file:///var/mobile/Containers/Data/Application/81EC85D8-5C35-4090-8F2E-5229775F2D43/Documents/YiuPai.sqlite";
}

我该如何解决这个问题?我想我犯了你的错误。请尝试如下设置您的storeUrl:

let storeUrl = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!.appendingPathComponent("YiuPai.sqlite")

我想我犯了你的错误。请尝试如下设置您的storeUrl:

let storeUrl = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!.appendingPathComponent("YiuPai.sqlite")