【问题标题】:Cannot convert value of type 'URL' to expected argument type 'Bool' [closed]无法将“URL”类型的值转换为预期的参数类型“Bool”[关闭]
【发布时间】:2020-06-21 09:23:45
【问题描述】:

在下面的代码中,错误是这样来的。错误就像

“无法将'URL'类型的值转换为预期的参数类型'Bool']”

private func saveImages(){

        let document = try !FileManager.default.url(for:.documentDirectory , in : .userDomainMask , appropriateFor:  nil , create: true) //[error is = Cannot convert value of type 'URL' to expected argument type 'Bool']
        print (document)

        let imgUrl = document.appendingPathComponent("1.jpg" , isDirectory : true)
        print(imgUrl.path)

        if FileManager.default.fileExists(atPath: imgUrl.path){
            do{
                try UIImageJPEGRepresentation(UIImage(named : "1.jpg") !)?.write (to :imgUrl)
                print("image added successfully")
            }catch{
                print("image not added")
            }

        }


    }

【问题讨论】:

    标签: ios swift xcode swift4 mobile-application


    【解决方案1】:

    有一个微妙但关键的错字。

    替换

    try !FileManager
    

    有

    try! FileManager
    

    【讨论】:

    • 这是一个不错的收获!应该解决它
    猜你喜欢
    • 2016-10-12
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多