3

When I declare the SDWebImageCompletionBlock, it throws this error before compiling "Use of undeclared type type 'SDWebImageCompletionBlock':

let block: SDWebImageCompletionBlock! = {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType!, imageURL: NSURL!) -> Void in
        }

When I set the imageView w/o the completion block, this works:

self.imgView!.sd_setImageWithURL(url, placeholderImage: UIImage(named: "my_img_placeholder"))
Tim Nuwin
  • 2,775
  • 2
  • 29
  • 63

2 Answers2

2

I don't see any issues with your code. I tried it and it works for me with swift 2.1 and Xcode 7.2. Are you sure you have imported the SDWebImage to your source code correctly?

This piece of code works for me:

import SDWebImage

class MyClass {
   func myFunction() {
      let block = {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType, imageURL: NSURL!) -> Void in
         // completion code here
      }
      imageView.sd_setImageWithURL(NSURL(string: stringUrl!)!, placeholderImage: UIImage(named: "placeholder_image"), completed: block)
   }
}
dzensik
  • 695
  • 11
  • 20
0

swift 3 use this

     activityIndicator.startAnimating()

     let block: SDWebImageCompletionBlock = {(image, error, cacheType, imageURL) -> Void in
     activityIndicator.stopAnimating()

}

     imageView.sd_setImage(with: picture_url, placeholderImage: UIImage(named: "placeholder"), options:
Lalit kumar
  • 1,797
  • 1
  • 8
  • 14