How to use completion block using SDWebImage in Swift 3.0?

Parvezkhan picture Parvezkhan · Nov 16, 2016 · Viewed 19.3k times · Source

Am using SDWebImage to download image. I want to do further operation if image is downloaded successfully.

cell.appIcon.sd_setImage(with: url, placeholderImage: UIImage.init(named: "App-Default"), completed: {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType, imageURL: URL!) -> Void in
      // Perform operation. 
})

But I am getting error:

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

Answer

Parvezkhan picture Parvezkhan · Nov 16, 2016

Finally solved.

cell.appIcon.sd_setImage(with: url!, placeholderImage: UIImage(named: "App-Default"),options: SDWebImageOptions(rawValue: 0), completed: { (image, error, cacheType, imageURL) in
 // Perform operation.
})