Lukas Bimba
Lukas Bimba

Reputation: 826

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

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

Upvotes: 0

Views: 5921

Answers (1)

Vini App
Vini App

Reputation: 7485

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

Upvotes: 1

Related Questions