Swift 4错误:"无法转换类型' URLRequest'的值预期参数类型' URL!'"

时间:2017-10-04 20:49:52

标签: ios swift image url nsurlrequest

正如标题所说的那样。我收到此错误并且不确定这是否与Swift 4转换有关。我一直在尝试解决代码,但没有运气,所以决定把这个问题提出来。这个错误正在上线:" cell.businessPostImage.setImageWith(postRequest,"。谢谢。

cell.businessPostImage.image = nil
        if let postURL = URL(string: downloadURL) {
            let postRequest = URLRequest(url: postURL)
            cell.businessPostImage.setImageWith(postRequest, placeholderImage: nil, options:
            { (imageRequest, imageResponse, image) in
                    cell.businessPostImage.contentMode = UIViewContentMode.scaleToFill
                    cell.businessPostImage.image = image
            }, completed: { (imageRequest, imageResponse, error) -> Void in
                // failure downloading image
                print("Error downloading Firebase post image")
                print(error)
            })
        }

This is the error its getting thrown WITH the edit

1 个答案:

答案 0 :(得分:1)

你必须这样使用:

if let postURL = URL(string: downloadURL) {
    let postRequest = URLRequest(url: postURL)
    cell.businessPostImage.setImageWith(postURL, placeholderImage: nil, options: SDWebImageOptions.ProgressiveDownload, completed: { (imageRequest, imageResponse, error) -> Void in
        // failure downloading image
        print("Error downloading Firebase post image")
        print(error)
    })
}