Swift 4 Error: "Cannot convert value of type 'URLRequest' to expected argument type 'URL!'"

Question

Just what the title says. I am getting this error thrown and not sure if this has to do with the Swift 4 conversion. I have been trying to work around the code but no luck yet so decided to throw this question up on SO. This error is getting thrown on line: "cell.businessPostImage.setImageWith(postRequest,". Thanks.

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


Show source
| url   | swift   | ios   | image   | nsurlrequest   2017-10-04 22:10 1 Answers

Answers to Swift 4 Error: "Cannot convert value of type 'URLRequest' to expected argument type 'URL!'" ( 1 )

  1. 2017-10-05 00:10

    You have to use like this :

    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)
        })
    }
    

Leave a reply to - Swift 4 Error: "Cannot convert value of type 'URLRequest' to expected argument type 'URL!'"

◀ Go back