SDWebImage, Swift: SDWebImageRefreshCached unresol

2019-07-15 08:33发布

问题:

Strange.. something simple that is in the docs doesn't seem to work with Swift. See below code. Where exactly is "SDWebImageRefreshCached" when using Swift??

self.profileImageView.sd_setImageWithURL(profileImageUrl, placeholderImage:  UIImage(named: "default_profile_image"), options: SDWebImageRefreshCached)

回答1:

In Swift, the enums are exposed slightly differently.

You would be looking for SDWebImageOptions.RefreshCached, or .RefreshCached for short.

Your line of code thus would be:

self.profileImageView.sd_setImageWithURL(profileImageUrl, placeholderImage:  UIImage(named: "default_profile_image"), options: .RefreshCached)


回答2:

You can try this code:

.RefreshCached is change to .refreshCached in SDWebImage 4.0.0

//SDWebImage 4.0.0
self.profileImageView.sd_setImage(with: yourImageUrl, placeholderImage: UIImage("Your placeholder image name"), options: .refreshCached)