swift - 多线程下载图片
程序员文章站
2024-02-20 15:11:58
...
swift - 多线程下载图片
private func fetchBackgroundImageData() {
backgroundImage = nil
if let url = self.backgroundURL {
DispatchQueue.global(qos: .userInitiated).async {
if let imageData = try? Data(contentsOf: url) {
DispatchQueue.main.async {
if url == self.backgroundURL {
self.backgroundImage = UIImage(data: imageData)
}
}
}
}
}
}