DEV Community

Discussion on: Loading Images from URLs in Swift without URLSession

cupnoodle profile image

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 { ... }.

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!

shawonashraf profile image
Shawon Ashraf Author

Thanks for the heads up! Will update the snippets.