Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 3.13 KB

README.md

File metadata and controls

80 lines (63 loc) · 3.13 KB

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