Why does not copy database.db from bundle to document directory in swift 3? [duplicate]

*爱你&永不变心* 提交于 2019-12-06 04:41:13

Solved

    let bundlePath = Bundle.main.path(forResource: "cry", ofType: ".db")
    let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
    let fileManager = FileManager.default
    let fullDestPath = URL(fileURLWithPath: destPath).appendingPathComponent("cry.db")
    if fileManager.fileExists(atPath: fullDestPath.path){
        print("Database file is exist")
        print(fileManager.fileExists(atPath: bundlePath!))
    }else{
        do{
            try fileManager.copyItem(atPath: bundlePath!, toPath: fullDestPath.path)
        }catch{
            print("\n",error)
        }
    }  

I added .path to my destination address and it works now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!