Updated 26 October 2021
Some times we need to draw the UIView and also images due to that reason it will take some time to load from url and interrupt main thread .
due to that reason we need to make separate queue and store the images , and it will effect after the successfully loaded.
Need some steps to follow:
1: Define this method
1 |
var queue = OperationQueue() |
2: Now define the operation count (size of queue)
1 |
var queue = OperationQueue() |
3: Now its time to load the images from URL and set to image View.
1 2 3 4 5 6 7 8 9 10 11 12 |
DispatchQueue.global(qos: .background).async { let operation1 = BlockOperation(block: { let data = try? Data(contentsOf: url) if data != nil{ let img = UIImage(data: data!) OperationQueue.main.addOperation({ banner.image = img }) } }) self.queue.addOperation(operation1) } |
note: here banner is UIimageView.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.