
The code about MessageImageLoader looks Как ниже.
Код: Выделить всё
class SomeView: UIView {
let listView = ListView()
func update(with data: SomeData) {
listView.update(with: data)
}
}
class ListView: UIView {
private var imageLoaders: [MessageImageLoader] = []
func update(with data: SomeData) {
imageLoaders.removeAll()
data.ids.forEach {
let imageLoader = MessageImageLoader(imageInfo: ["...": $0.sth])
imageLoaders.append(imageLoader)
imageLoader.load { [weak self] _ in
self?.imageLoaders.remove(imageLoader)
}
}
}
}
class MessageImageLoader {
// ...
func load(completion: @escaping (UIImage?) -> Void) {
Task { [weak self] in
guard let self else { return }
// a bunch of await call inside
}
}
}
Я должен отменить задачу перед повторным использованием?
Код: Выделить всё
imageInfoПодробнее здесь: https://stackoverflow.com/questions/797 ... dictionary
Мобильная версия