Open vinhnx opened 8 months ago
import UIKit // Before let image = UIImage(named: "big-image") imageView.image = image // After let image = UIImage(named: "big-image") image?.prepareForDisplay { [weak self] preparedImage in DispatchQueue.main.async { self?.imageView.image = preparedImage } } // using Swift Concurrency let image = UIImage(named: "big-image") Task { imageView.image = await image?.byPreparingForDisplay() }
https://www.swiftwithvincent.com/blog/bad-practice-loading-a-large-image-on-the-main-thread
https://www.swiftwithvincent.com/blog/bad-practice-loading-a-large-image-on-the-main-thread