Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About WebCache's sd_setImageWithURL with swift

I'm using WebCache with swift.

When I set String into sd_setImageWithURL directly like following, it's displayed correctly.

imageView?.sd_setImageWithURL(NSURL(string: "http://imgfp.hotp.jp/IMGH/86/49/P018678649/P018678649_238.jpg"), placeholderImage: nil, options: SDWebImageOptions.CacheMemoryOnly, completed: {[unowned self] (image: UIImage!, error: NSError!, type: SDImageCacheType, url: NSURL!) -> Void in
    ....

But, I set like following, it's not displayed..

if let imageURL:String = shop.img {
    print(imageURL) // same as above
    self.imageView?.sd_setImageWithURL(NSURL(string: imageURL), placeholderImage: nil, options: SDWebImageOptions.CacheMemoryOnly, completed: {[unowned self] (image: UIImage!, error: NSError!, type: SDImageCacheType, url: NSURL!) -> Void in
        ....
}

What's wrong??

like image 350
naohide_a Avatar asked Dec 09 '25 17:12

naohide_a


1 Answers

It's very simple:

if let strImage = "http://imgfp.hotp.jp/IMGH/86/49/P018678649/P018678649_238.jpg"{
    self.imageView.sd_setImageWithURL(NSURL(string: strImage), completed: { (img, error, type, urls) in
    })
}

Use imageView.image to display wherever you want.

like image 129
Arshad Shaik Avatar answered Dec 12 '25 07:12

Arshad Shaik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!