SDWebImage: Crash in swift, when I use self.xxxx in the completed block

self.imageView.sd_setImageWithURL(MYIMAGEURL
            , placeholderImage: nil
            , options: SDWebImageOptions.RetryFailed
            , progress: {(receivedSize: Int!, expectedSize: Int!) in

            }
            , completed:{(image: UIImage?, error: NSError?, cacheType: SDImageCacheType!, imageURL: NSURL?) in
                if image {
                    UIView.transitionWithView(self.imageView
                        , duration: 0.3
                        , options: UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.TransitionCrossDissolve
                        , animations: {

                        }
                        , completion: {(finished) in

                        })
                }
            })

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 37 (6 by maintainers)

Most upvoted comments

Thanks @lubert, thats it! Many thanks for this workaround. Just have to call like this

    SDWebImageDownloader.sharedDownloader().downloadImageWithURL(myImageUrl, options: nil, progress: nil, completed: {[weak self] (image, data, error, finished) in
        if let wSelf = self {
            // do what you want with the image/self
            println("have an image now")
            self?.imageView.image = image
        }
    })