Image from Remote URL Using SDWebImageSwiftUI
Let’s learn how to present an image downloaded from a remote URL using SDWebImageSwiftUI with just one line of code! SwiftUI 2.0 & Xcode 12
Difficulty: Beginner | Easy | Normal | Challenging
Environment : Xcode 12, SwiftUI, Package Manager & SDWebImageSwiftUI
Create a new Xcode Project
Open Xcode > New Project > App Template > SwiftUI Interface and call it WebImage
Add SDWebImageSwiftUI via Package Manager
If you are not logged in to GitHub, first follow the tutorial from Apple
Go to file > Swift Packages > Add Packages Dependencies > insert “https://github.com/SDWebImage/SDWebImageSwiftUI" > Finish
If everything run smoothly, you can see a new section created in Xcode called Swift Packages Dependencies and you will be able to import the framework SDWebImageSwiftUI.
Let’s code!
Go to your ContentView.swift file and import the framework at the top:
Then, declare a WebImage such as you would declare an Image in SwiftUI, copy the code below inside the body
:
That’s it! SDWebImageSwiftUI make it super easy to present an image from a remote url, with 3 others lines, we gave it a frame and an aspect ratio and we are good to go!
Thanks for reading! Consider subscribing to enjoy unlimited access to my articles and all of Medium through my referral link.
Originally published at https://swiftproductions.substack.com.