Error Domain=Kingfisher.KingfisherError Code=5002 "Retrieving resource succeeded, but this source is not the one currently expected. Result: RetrieveImageResult(image:
Hi ~ 5002 means that, the resource task is finished, but it is not the one expected now. This usually happens when you set another resource on the view without cancelling the current on-going one.
would please show me your code?
Hey, @soso-su
As @ixongju mentioned, it means you have set an image to the image view again before the previous task finished. The error is reported when the previous processing is done, but it should not be set to the current image view.
This error would happen a lot if you use it in a reusable view, like a table view cell or a collection view cell. When scrolling, the cell will be reused and maybe it set new images. However, it will not cancel the previous one by default. So you will have this issue. In this case, it should be fine to just ignore it.
If you'd like to stop it, a possible way is canceling the task at a proper time. Check this tip for more.
Hi ~
5002means that, the resource task is finished, but it is not the one expected now. This usually happens when you set another resource on the view without cancelling the current on-going one.would please show me your code?
So here's my code, this is from UICollectionViewCell, which is a very old project that I took on recently, and I discovered this problem:
var newImage: imageNews? {
didSet {
let size = CGSize(width: screenWidth - 2 * kMargin, height: CGFloat(MAXFLOAT))
let abstractHeight = newImage?.image_desc?.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: UIFont.fontWith( 18)!], context: nil).size.height
abstractLabelHeight.constant = abstractHeight! + 5
abstractLabelBottom.constant = SafeAreaBottomHeight + 50
self.layoutIfNeeded()
let abstractAttributeString = NSAttributedString(string: newImage!.image_desc!, attributes: [NSAttributedString.Key.font: UIFont.fontWith( 17)!])
let countAttributeString = NSMutableAttributedString(string: "/(count!) ", attributes: [NSAttributedString.Key.font: UIFont.fontWith( 13)!])
countAttributeString.append(abstractAttributeString)
let numberAttributeString = NSMutableAttributedString(string: String(index!), attributes: [NSAttributedString.Key.font: UIFont.fontWith( 17)!])
numberAttributeString.append(countAttributeString)
self.activityView.isHidden = false
self.activityView.startAnimating()
imageView.kf.setImage(with: URL(string: newImage!.image_url!), placeholder: nil, options: nil, progressBlock: { (receivedSize, totalSize) in
}) { (image, error, cacheType, url) in
if error != nil{
self.loadingView.showNoNetwork()
}else {
self.loadingView.isHidden = true
}
self.activityView.isHidden = true
self.activityView.stopAnimating()
self.imageScrollView.image = image
self.enabledPenetrateScrollViewEvent()
}
}
}
}
Hey, @soso-su
As @ixongju mentioned, it means you have set an image to the image view again before the previous task finished. The error is reported when the previous processing is done, but it should not be set to the current image view.
This error would happen a lot if you use it in a reusable view, like a table view cell or a collection view cell. When scrolling, the cell will be reused and maybe it set new images. However, it will not cancel the previous one by default. So you will have this issue. In this case, it should be fine to just ignore it.
If you'd like to stop it, a possible way is canceling the task at a proper time. Check this tip for more.
Yes, please help me to look at my code
Hi, @soso-su
I think you can try this:
on the cell, specify a property to receive the result of imageView.kf.setImage() which is a DownloadTask(API Reference - DownloadTask), then on the didSet observer of this property, call the cancel() method on the oldValue.
as follow:
private var task: DownloadTask? {
didSet {
oldValue?.cancel()
}
}
var newImage: imageNews? {
// other code keeps remain
task = imageView.kf.setImage(with: URL(string: newImage!.image_url!)...
// ...
}
It is not an issue and the related topic is already covered in the our wiki. See my comments above and I am closing it.
Most helpful comment
Hey, @soso-su
As @ixongju mentioned, it means you have set an image to the image view again before the previous task finished. The error is reported when the previous processing is done, but it should not be set to the current image view.
This error would happen a lot if you use it in a reusable view, like a table view cell or a collection view cell. When scrolling, the cell will be reused and maybe it set new images. However, it will not cancel the previous one by default. So you will have this issue. In this case, it should be fine to just ignore it.
If you'd like to stop it, a possible way is canceling the task at a proper time. Check this tip for more.