Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

Can't set completion SDWebImageCompletionBlock swift 3.0

working swift 2.2 bellow block.

 AvtarImgview.setImageWith(URL(string: https://....), completed: { (image : UIImage!, error : NSError!, cacheType : SDImageCacheType,imageURL : URL!) -> Void in
        if image != NSNotFound && image != nil
        {
            let cgref : CGImageRef? = image.cgImage
            let cim: CIImage? = image.ciImage
           if cgref == nil && cim == nil
           {
                self.AvtarImgview.image = UIImage(named: "iconNoImageDeal")
           }
        }else
        {
            self.AvtarImgview.image = UIImage(named: "iconNoImageDeal")
        }

 }, usingActivityIndicatorStyle: UIActivityIndicatorViewStyle.gray)

Geting Error swift 3.0:-

Cannot convert value of type '(UIImage!, NSError!, SDImageCacheType, URL!) -> Void' to expected argument type 'SDWebImageCompletionBlock!'

Any buddy can help me for convert this block in swfit 3.0.

Thanks in advance.

Upvotes: 2

Views: 2363

Answers (1)

Vasily  Bodnarchuk
Vasily Bodnarchuk

Reputation: 25294

Try this code:

    let urlString = "https://...."
    let url = URL(string: urlString)
    imageView.contentMode = .scaleAspectFit
    imageView.sd_setImage(with: url) { (image, error, imageCacheType, imageUrl) in
        if image != nil {
            print("image found")
        }else
        {
            print("image not found")
        }
    }

Upvotes: 3

Related Questions