Reputation: 967
I'm using SDWebImage
in my Swift app to download images to my tableview but I'm getting a simple error that I don't know how to fix. I finished converting my project from Objective C to Swift.
Code I'm using
let imgURL = (testObject.value(forKey: "testURL"))
self.myImageView.sd_setImage((with: imgURL as! URL!), placeholderImage: UIImage(imageNamed: "no-image.png"))
self.myImageView.contentMode = .scaleAspectFit
Error:
Argument labels '(imageNamed:)' do not math any available overloads
Upvotes: 0
Views: 268
Reputation: 38667
You can try correct naming for UIImage initializer, and improved cast to URL:
let imgURL = testObject.value(forKey: "testURL") as! URL
self.myImageView.sd_setImage(with: imgURL, placeholderImage: UIImage(named: "no-image.png"))
But better, you can use an image literal for "no-image":
let imgURL = testObject.value(forKey: "testURL") as! URL
self.myImageView.sd_setImage(with: imgURL, placeholderImage: #imageLiteral(resourceName: "no-image.png"))
And best would be to avoid the forced unwrap.
let imgURL = testObject.value(forKey: "testURL") as? URL
self.myImageView.sd_setImage(with: imgURL, placeholderImage: #imageLiteral(resourceName: "no-image.png"))
[update: after author claims that value is a String]
If value of "testURL" is a String, then you can't unwrap it as an URL. This code may help:
let imgString = testObject.value(forKey: "testURL") as? String ?? ""
self.myImageView.sd_setImage(with: URL(string: imgString), placeholderImage: #imageLiteral(resourceName: "no-image.png"))
Upvotes: 1
Reputation: 2095
it worked for me. Try this: -
self.imageView.sd_setImage(with: URL(string: item.image!))
You need to cast the string to URL in order for this to work.
Upvotes: 0
Reputation: 2098
This might be a change with Swift 3, but it should be UIImage(named: "no-image.png")
Upvotes: 0