DEV Community

Discussion on: Loading Images from URLs in Swift without URLSession

Collapse
 
cupnoodle profile image
Axel

Just a note, Data(contentsOf: URL) is synchronous, if you run this on the main thread and the image takes a while to load, the User Interface on the app will be not responsive to the user, you should wrap it with DispatchQueue.global().async { ... }.

And also avoid using DispatchQueue.main.sync on main thread (by default your code is already running on main thread), as it is synchronous and might result in deadlock!

Collapse
 
shawonashraf profile image
Shawon Ashraf

Thanks for the heads up! Will update the snippets.