Created
March 19, 2025 08:30
-
-
Save gaeng2y/b0fb42de2cee6f0ca925296966f79607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @MainActor | |
| class MyDelegate: UICollectionViewDelegate { | |
| var thumbnailTasks: [IndexPath: Task<Void, Never>] = [:] | |
| func collectionView(_ view: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt item: IndexPath) { | |
| let ids = getThumbnailIDs(for: item) | |
| thumbnailTasks[item] = Task { | |
| defer { thumbnailTasks[item] = nil } | |
| let thumbnails = await fetchThumbnails(for: ids) | |
| display(thumbnails, in: cell) | |
| } | |
| } | |
| func collectionView(_ view: UICollectionView, didEndDisplay cell: UICollectionViewCell, forItemAt item: IndexPath) { | |
| thumbnailTasks[item]?.cancel() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment