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?'
This one also works with swift 3 :
According to the
typedef
in the framework you're using:an
SDExternalCompletionBlock
consists of optional parameters as indicated by_Nullable
. Therefor your code should be written like this:Since the compiler knows the types of the completion block's parameters (from the function declaration) you can write the code more succinctly and (IMO) easier to read like this:
Updates: SWIFT 5 SDWebImage 5.x.x
========================================================================
Try this, hope this will work fine
SWIFT 4 version
Important! Don't forget to send self as weak or unowned (like this [self weak]/[self unowned]) to the block, when it is necessary, to avoid retain cycles.
Example:
Finally solved.