Skip to content

Forge4Flow/SwiftUI-IPFSImage

 
 

Repository files navigation

SwiftUI IPFSImage

⚠️ UNDER ACTIVE DEVELOPMENT - DO NOT USE YET

IPFSImage is AsyncImage, but with init options to load IPFS-based images and with cache capabilities. IPFSImage is based on the amazing work of Lorenzo Fiamingo with CachedAsyncImage

Usage

To use IPFSImage simply import the package and use IPFSImage instead of AsyncImage.

IPFSImage(cid: "Your IPFS Image CID/HASH")

This will request a resizeable image from the specified IPFS cid/hash. IPFSImage also provides default loading and error states on top of AsyncImage. IPFSImage includes the same API and behavior as AsyncImage, so you can use any of the default AsyncImage initializers.

In addition to AsyncImage initializers, you have the ability to specify the cache you want to use (by default URLCache.shared is used), and to use URLRequest instead of a cid:

IPFSImage(urlRequest: logoURLRequest, urlCache: .imageCache)
// URLCache+imageCache.swift

extension URLCache {
    
    static let imageCache = URLCache(memoryCapacity: 512*1000*1000, diskCapacity: 10*1000*1000*1000)
}

Remember when setting the cache the response (in this case our image) must be no larger than about 5% of the disk cache (See this discussion).

Installation

  1. In Xcode, open your project and navigate to FileSwift PackagesAdd Package Dependency...
  2. Paste the repository URL (https://github.com/EurekaDAO/SwiftUI-IPFSImage) and click Next.
  3. Click Finish.

About

IPFSImage is the simplest way to add IPFS Images (with caching!) to your SwiftUI Project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%