swift - 无法设置完成 SDWebImageCompletionBlock swift 3.0

标签 swift swift3 sdwebimage

工作 swift 2.2 波纹管 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)

Swift 3.0 出现错误:-

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

哪位 friend 可以帮我在swfit 3.0中转换这个 block 。

提前致谢。

最佳答案

试试这个代码:

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

关于swift - 无法设置完成 SDWebImageCompletionBlock swift 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39567704/

相关文章:

swift - 如何找出某个 OSX 版本可用的 API 版本?

swift3 - swift 3 urlRequest session.dataTask 未触发

ios - 如何使用SDWebImage向UIButton添加“前景”图像

swift - 为什么预先识别的Cell在Sub viewcontroller中无效? iOS系统

swift - AVAudioSourceNode如何设置设置格式

arrays - 获取数据到 TableView

ios - 如何在 UIWebview 中包含自定义字体?

ios - 代码 8 : Cannot inherit from non-open class

ios - 加载图像时出现 SDWebImage 错误

ios - 如何在我的项目中使用 SDWebImage