无法转换类型"字符串"的值预期参数类型" URL"

时间:2017-07-02 15:15:29

标签: swift sqlite

do中的陈述未被执行。任何人都可以帮我解决这个问题?非常感谢!

class func copyFile(fileName: NSString){

    let fileManager = FileManager.default

    let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)

    guard documentsURL.count != 0 else{
        return
    }

    let finalDatabaseURL = documentsURL.first!.appendingPathComponent(fileName as String)

    if !((try? finalDatabaseURL.checkResourceIsReachable()) ?? false){
        print("Database does not exist in documents")

        let documentsURL = Bundle.main.resourceURL?.appendingPathComponent(fileName as String)

        do{
            try fileManager.copyItem(at: (documentsURL?.path)!, to: finalDatabaseURL.path)

        }catch let error as NSError{
            print("Couldn't copy file to final location!Error:\(error.description)")
        }
    }else{
        print("Database file found at path:\(finalDatabaseURL.path)")
    }


}

1 个答案:

答案 0 :(得分:0)

copyItem(at srcURL: URL, to dstURL: URL)获取两个网址参数,然后传递字符串。

要么你使用它。

try fileManager.copyItem(at: documentsURL!, to: finalDatabaseURL)

try fileManager.copyItem(atPath: (documentsURL?.path)!, toPath: finalDatabaseURL.path)