Search code examples
swiftswift3sdwebimage

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.


Solution

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