You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
switch completion {
case .failure(let error):
self?.error = .unexpectedError(error.localizedDescription)
case .finished:
self?.error = nil
}
} receiveValue: { [weak self] response in
guard let self else { return }
self.profiles = response?.currentItems ?? []
if !profiles.isEmpty {
if let currentItems = response?.currentItems {
if let urlStrings = response?.currentItems?.first.flatMap({ $0.getPhotos() }) {
let urls = urlStrings.compactMap { URL(string: $0) }
**KingfisherImagePrefetcher.shared.startPrefetching(urls: urls, for: .profile)**
}
self.currentProfile = currentItems.first
}
} else {
self.currentProfile = nil
}
}
.store(in: &cancellables)
}
`
Logs:
`
These resources are prefetched: []
These resources are skipped: []
These resources are failed: [Kingfisher.KF.ImageResource(cacheKey: "stage04.ndcdn.com/media/drv/c39/e19/86c/c39e1986-cb03-4f84-a7de-743ececc2d14.0aefa39cdaa4f3b4b16e68c8f96b555a_drv30.jpg?1712233859", downloadURL: stage04.ndcdn.com/media/drv/c39/e19/86c/c39e1986-cb03-4f84-a7de-743ececc2d14.0aefa39cdaa4f3b4b16e68c8f96b555a_drv30.jpg? ... 12233859), Kingfisher.KF.ImageResource(cacheKey: "stage04.ndcdn.com/media/drv/011/bb1/843/011bb184-36e7-45ab-9eea-b9753c210726.d27dd5504dbfd112090c834000d3a96a_drv30.jpg?1712233826", downloadURL: stage04.ndcdn.com/media/drv/011/bb1/843/011bb184-36e7-45ab-9eea-b9753c210726.d27dd5504dbfd112090c834000d3a96a_drv30.jpg? ... 12233826)]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
ImagePrefetcher always returns every passed url as a failed, none is skipped or successfull. Implemented in a pure SwiftUI.
Here is the base code (implementation and calls) and logs (urls are valid):
Base code
- implementation
``
import Foundation
import Kingfisher
final class KingfisherImagePrefetcher {
static let shared = KingfisherImagePrefetcher()
var prefetchers: [Location: Kingfisher.ImagePrefetcher] = [:]
}
extension KingfisherImagePrefetcher {
func startPrefetching(urls: [URL], for location: Location) {
prefetchers[location] = Kingfisher.ImagePrefetcher(urls: urls) {
skippedResources, failedResources, completedResources in
AppLog.network.error("These resources are prefetched: (completedResources)")
AppLog.network.error("These resources are skipped: (skippedResources)")
AppLog.network.error("These resources are failed: (failedResources)")
if !failedResources.isEmpty {
for resource in failedResources {
AppLog.network.error("Failed URL: (resource.downloadURL.absoluteString)")
}
}
}
prefetchers[location]?.start()
}
}
``
- calls
`
func getProfiles() {
isLoading = true
let request = PaginationRequest(
page: 1,
perPage: 10
)
profileManager.getProfiles(page: request)
.receive(on: DispatchQueue.main)
.sink { [weak self] completion in
self?.isLoading = false
Logs:
`
These resources are prefetched: []
These resources are skipped: []
These resources are failed: [Kingfisher.KF.ImageResource(cacheKey: "stage04.ndcdn.com/media/drv/c39/e19/86c/c39e1986-cb03-4f84-a7de-743ececc2d14.0aefa39cdaa4f3b4b16e68c8f96b555a_drv30.jpg?1712233859", downloadURL: stage04.ndcdn.com/media/drv/c39/e19/86c/c39e1986-cb03-4f84-a7de-743ececc2d14.0aefa39cdaa4f3b4b16e68c8f96b555a_drv30.jpg? ... 12233859), Kingfisher.KF.ImageResource(cacheKey: "stage04.ndcdn.com/media/drv/011/bb1/843/011bb184-36e7-45ab-9eea-b9753c210726.d27dd5504dbfd112090c834000d3a96a_drv30.jpg?1712233826", downloadURL: stage04.ndcdn.com/media/drv/011/bb1/843/011bb184-36e7-45ab-9eea-b9753c210726.d27dd5504dbfd112090c834000d3a96a_drv30.jpg? ... 12233826)]
Failed URL: stage04.ndcdn.com/media/drv/c39/e19/86c/c39e1986-cb03-4f84-a7de-743ececc2d14.0aefa39cdaa4f3b4b16e68c8f96b555a_drv30.jpg?1712233859
Failed URL: stage04.ndcdn.com/media/drv/011/bb1/843/011bb184-36e7-45ab-9eea-b9753c210726.d27dd5504dbfd112090c834000d3a96a_drv30.jpg?1712233826
`
Thanks
Beta Was this translation helpful? Give feedback.
All reactions