{"id":26099323,"url":"https://github.com/chris-swift-dev/remoteimage","last_synced_at":"2025-04-12T13:42:23.024Z","repository":{"id":51938085,"uuid":"202430977","full_name":"chris-swift-dev/RemoteImage","owner":"chris-swift-dev","description":"Swift package for a SwiftUI remote image view","archived":false,"fork":false,"pushed_at":"2022-04-11T19:04:51.000Z","size":341,"stargazers_count":81,"open_issues_count":2,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T14:02:28.948Z","etag":null,"topics":["catalyst","icloud","icloud-photos","ios","mac-os","macos","phasset","remoteimage","remoteimage-swiftui","swift","swift-package","swift-ui","swiftui","swiftui-components","swiftui-example"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chris-swift-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-14T21:50:55.000Z","updated_at":"2025-02-08T16:53:57.000Z","dependencies_parsed_at":"2022-08-23T15:21:58.958Z","dependency_job_id":null,"html_url":"https://github.com/chris-swift-dev/RemoteImage","commit_stats":null,"previous_names":["chris-swift-dev/remoteimage","crelies/remoteimage"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-swift-dev%2FRemoteImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-swift-dev%2FRemoteImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-swift-dev%2FRemoteImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-swift-dev%2FRemoteImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chris-swift-dev","download_url":"https://codeload.github.com/chris-swift-dev/RemoteImage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248574591,"owners_count":21127042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["catalyst","icloud","icloud-photos","ios","mac-os","macos","phasset","remoteimage","remoteimage-swiftui","swift","swift-package","swift-ui","swiftui","swiftui-components","swiftui-example"],"created_at":"2025-03-09T16:37:06.864Z","updated_at":"2025-04-12T13:42:23.002Z","avatar_url":"https://github.com/chris-swift-dev.png","language":"Swift","readme":"# RemoteImage\n\n[![Swift 5.3](https://img.shields.io/badge/swift-5.3-green.svg?longCache=true\u0026style=flat-square)](https://developer.apple.com/swift)\n[![Platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS-lightgrey.svg?longCache=true\u0026style=flat-square)](https://www.apple.com)\n[![Current Version](https://img.shields.io/github/v/tag/crelies/RemoteImage?longCache=true\u0026style=flat-square)](https://github.com/crelies/RemoteImage)\n[![Build status](https://github.com/crelies/RemoteImage/actions/workflows/build.yml/badge.svg)](https://github.com/crelies/RemoteImage/actions/workflows/build.yml)\n[![Code coverage](https://codecov.io/gh/crelies/RemoteImage/branch/dev/graph/badge.svg?token=DhJyoUKNPM)](https://codecov.io/gh/crelies/RemoteImage)\n[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg?longCache=true\u0026style=flat-square)](https://en.wikipedia.org/wiki/MIT_License)\n\nThis Swift package provides a wrapper view around the existing **SwiftUI** `Image view` which adds support for showing and caching remote images.\nIn addition you can specify a loading and error view.\n\nYou can display images from a specific **URL** or from the **iCloud** (through a `PHAsset` identifier).\n\n## 💡 Installation\n\nAdd this Swift package in Xcode using its Github repository url. (File \u003e Swift Packages \u003e Add Package Dependency...)\n\n## 🧭 How to use\n\nJust pass a remote image url or the local identifier of a `PHAsset` and `ViewBuilder`s for the error, image and loading state to the initializer. That's it 🎉\n\nClear the image cache through `RemoteImageService.cache.removeAllObjects()`.\n\n## 📖 Examples\n\nThe following code truly highlights the **simplicity** of this view:\n\n**URL example:**\n```swift\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(type: .url(url), errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\n**PHAsset example:**\n```swift\n\nRemoteImage(type: .phAsset(localIdentifier: \"541D4013-D51C-463C-AD85-0A1E4EA838FD\"), errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\n## Custom `RemoteImageURLDataPublisher`\n\nUnder the hood the `URLSession.shared` is used by default as the `RemoteImageURLDataPublisher` to fetch the image at the specified URL.\nYou can specify a custom publisher through the`remoteImageURLDataPublisher` parameter.\nAs an example that's how you could add support for low data mode to the `RemoteImage` view.\n\n```swift\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(type: .url(url), remoteImageURLDataPublisher: {\n    let configuration = URLSessionConfiguration.default\n    // Enable low data mode support\n    configuration.allowsConstrainedNetworkAccess = false\n    return URLSession(configuration: configuration)\n}(), errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\n## Custom `RemoteImageService`\n\nIf you want complete control over the service responsible for managing the state of the view and for fetching the image you could pass an object conforming to the `RemoteImageService` protocol to the related initializer:\n\n```swift\nfinal class CustomService: RemoteImageService { ... }\n\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(type: .url(url), service: CustomService(), errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\nIn addition to that you could use the new `@StateObject` property wrapper introcuded in Swift by creating an instance of the default built-in `RemoteImageService` and using the above initializer:\n\n```swift\n@StateObject var service = DefaultRemoteImageServiceFactory.makeDefaultRemoteImageService()\n// or\n@StateObject var service = DefaultRemoteImageServiceFactory.makeDefaultRemoteImageService(remoteImageURLDataPublisher: yourRemoteImageURLDataPublisher)\n\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(type: .url(url), service: service, errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\n## Custom cache\n\nThe `RemoteImageService` uses a default cache. To use a custom one just conform to the protocol `RemoteImageCache` and set it on the type `RemoteImageService`.\n\n```swift\nRemoteImageService.cache = yourCache\n```\n\n## Custom cache key\n\nThe default cache uses the associated value of the related `RemoteImageType` as the key. You can customize this by setting a cache key provider through\n\n```swift\nRemoteImageService.cacheKeyProvider = { remoteImageType -\u003e AnyObject in\n    // return a key here\n}\n```\n\n## Migration from 0.1.0 -\u003e 1.0.0\n\nThe `url parameter` was refactored to a `type parameter` which makes it easy to fetch images at a URL or from the iCloud. \n\nChange\n```swift\n# Version 0.1.0\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(url: url, errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n\nto\n```swift\n# Version 1.0.0\nlet url = URL(string: \"https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026auto=format\u0026fit=crop\u0026w=1950\u0026q=80\")!\n\nRemoteImage(type: .url(url), errorView: { error in\n    Text(error.localizedDescription)\n}, imageView: { image in\n    image\n    .resizable()\n    .aspectRatio(contentMode: .fit)\n}, loadingView: {\n    Text(\"Loading ...\")\n})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchris-swift-dev%2Fremoteimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchris-swift-dev%2Fremoteimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchris-swift-dev%2Fremoteimage/lists"}