
The code about MessageImageLoader looks like unten.
Code: Select all
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
// and the completion is called finally.
}
}
}
Code: Select all
imageInfo