Christian Sousa
06/16/2020, 4:26 PMprivate fun getDataFromUrl(url: NSURL) {
NSURLSession.sharedSession.dataTaskWithURL(
url = url,
completionHandler = ::getCompletion.freeze()
).resume()
}
So with this, I will get data from a URL
After that, with my getCompletion
fun getCompletion(data: NSData?, response: NSURLResponse?, error: NSError?){
var downloadedImage = UIImage(data = data)
logo.setImage(image = downloadedImage)
logo.setHidden(false)
}
Where my logo is a UIImage.
Problem is, the getCompletion
is being called from a background thread and I’m trying to update something on the main thread.
Is there any way of doing this?
The goal is to be able to download the image asynchronously and after that, update the image I already have.
What I’m getting as an error is the following:
Main Thread Checker: UI API called on a background thread: -[UIImageView setImage:]