LoadableImage

1.0.0

Lightweight but useful loadable image component for SwiftUI with loading indicator, caching and image placeholder
achirkof/LoadableImage

What's New

1.0.0

2020-07-02T12:39:46Z

LoadableImage Header Logo LoadableImage

iOS macOS GitHub release (latest by date including pre-releases) Build Status codecov Swift Package Manager compatible License: MIT

Imgur

How to use

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.

Installation

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:

  1. File → Swift Packages → Add Package Dependency...
  2. Paste the repository URL: https://github.com/achirkof/LoadableImage.git

Future plans

  • Make ImageLoadable possible to work also with images from Assets 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 to downloadTask to decrease memory usage for big images

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 03:32:16 GMT-0900 (Hawaii-Aleutian Daylight Time)