Usage of ImageLoadable as simple as SwiftUI Image.
import SwiftUI
import LoadableImage
struct ContentView: View {
var body: some View {
HStack {
ImageLoadable(
source: "https://robohash.org/loadablerobot",
contentMode: .fit
)
.frame(width: 140, height: 140)
.background(Color.white)
.cornerRadius(10)
.shadow(radius: 10)
ImageLoadable(
source: "image_from_assets"
)
.frame(width: 140, height: 140)
.background(Color.white)
.cornerRadius(10)
.shadow(radius: 10)
}
}
}
}
It's also possible and very convenient while unit testing or using Xcode preview to create mock objects with local image even though in real life you load image from network. For example:
let robotFixture: Robot = Robot(
name: "Bender",
image: "image_from_assets
)
Consider Example project for further details.
Use Swift Package Manager to install. The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding LoadableImage as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/achirkof/LoadableImage.git", from: "1.0.0")
]
Or just add package to your project:
- File → Swift Packages → Add Package Dependency...
- Paste the repository URL: https://github.com/achirkof/LoadableImage.git
- Make
ImageLoadable
possible to work also with images fromAssets
catalog - Use URL caching to reduce network traffic and increase image loading speed
- Make
ImageLoadable
Codable to be able use it as type in the model - Rewrite from
dataTask
todownloadTask
to decrease memory usage for big images