{"id":1445,"url":"https://github.com/JanGorman/MapleBacon","last_synced_at":"2025-08-06T13:32:39.295Z","repository":{"id":24721250,"uuid":"28133215","full_name":"JanGorman/MapleBacon","owner":"JanGorman","description":"🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations","archived":false,"fork":false,"pushed_at":"2024-05-21T07:14:15.000Z","size":6927,"stargazers_count":343,"open_issues_count":0,"forks_count":51,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-22T02:29:06.685Z","etag":null,"topics":["caching","carthage","cocoapods","combine","image","image-download","swift","swift5","uiimageview","xcode"],"latest_commit_sha":null,"homepage":"","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/JanGorman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-17T10:52:04.000Z","updated_at":"2024-06-04T08:36:03.523Z","dependencies_parsed_at":"2023-02-12T15:01:44.468Z","dependency_job_id":"3cca5389-9fc3-45ff-a996-80f7d6e54811","html_url":"https://github.com/JanGorman/MapleBacon","commit_stats":{"total_commits":580,"total_committers":24,"mean_commits":"24.166666666666668","dds":0.4482758620689655,"last_synced_commit":"6159f58b0e0b0a35d367a6f51a20e1766625ef39"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FMapleBacon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FMapleBacon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FMapleBacon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FMapleBacon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JanGorman","download_url":"https://codeload.github.com/JanGorman/MapleBacon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905499,"owners_count":17989778,"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":["caching","carthage","cocoapods","combine","image","image-download","swift","swift5","uiimageview","xcode"],"created_at":"2024-01-05T20:15:46.621Z","updated_at":"2024-12-09T14:30:59.712Z","avatar_url":"https://github.com/JanGorman.png","language":"Swift","funding_links":[],"categories":["Media","Libs","Images [🔝](#readme)"],"sub_categories":["Image","Images","Other free courses"],"readme":"# MapleBacon\n\n[![CI](https://github.com/JanGorman/MapleBacon/workflows/CI/badge.svg)](https://github.com/JanGorman/MapleBacon/actions?query=workflow%3ACI)\n[![codecov.io](https://codecov.io/github/JanGorman/MapleBacon/coverage.svg)](https://codecov.io/github/JanGorman/MapleBacon)\n[![Version](https://img.shields.io/cocoapods/v/MapleBacon.svg?style=flat)](http://cocoapods.org/pods/MapleBacon)\n[![License](https://img.shields.io/cocoapods/l/MapleBacon.svg?style=flat)](http://cocoapods.org/pods/MapleBacon)\n[![Platform](https://img.shields.io/cocoapods/p/MapleBacon.svg?style=flat)](http://cocoapods.org/pods/MapleBacon)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![SPM](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.dropbox.com/s/mlquw9k6ogvspox/MapleBacon.png?raw=1\" height=\"210\"/\u003e\u003c/p\u003e\n\n# Introduction\n\nMapleBacon is a lightweight and fast Swift library for downloading and caching images.\n\n## Example\n\nThe folder `Example` contains a sample projects for you to try.\n\n## Requirements\n\n- Swift 5.1\n- iOS 10.0+\n- Xcode 10.2+\n\n## Installation\n\nMapleBacon is available through [CocoaPods](http://cocoapods.org). To install add it to your Podfile:\n\n```ruby\npod \"MapleBacon\"\n```\n\n[Carthage](https://github.com/Carthage/Carthage)\n\n```ogdl\ngithub \"JanGorman/MapleBacon\"\n```\n\nand [Swift Package Manager](https://swift.org/package-manager).\n\n## Usage\n\n### UIImageView\n\nThe most basic usage is via an extension on `UIImageView`. You pass it URL:\n\n```swift\nimport MapleBacon\n\nprivate var imageView: UIImageView!\n\nfunc someFunc() {\n  let url = URL(string: \"…\")\n  imageView.setImage(with: url)\n}\n```\n\nIf you want to add a placeholder while the image is downloading you specify that like this:\n\n```swift\nfunc someFunc() {\n  let url = URL(string: \"…\")\n  imageView.setImage(with: url, placeholder: UIImage(named: \"placeholder\"))\n}\n```\n\nIf your backend returns images that are not optimised for display, it's good practice to downsample them. MapleBacon comes with support for downsampling via `displayOptions`:\n\n```swift\nfunc someFunc() {\n  let url = URL(string: \"…\")\n  imageView.setImage(with: url, displayOptions: .downsampled)\n}\n```\n\n### Image Transformers\n\nMapleBacon allows you to apply transformations to images and have the results cached so that you app doesn't need to perform the same work over and over. To make your own transformer, create a class conforming to the `ImageTransforming` protocol. A transform can be anything you like, let's create one that applies a Core Image sepia filter:\n\n```swift\nprivate class SepiaImageTransformer: ImageTransforming {\n\n  // The identifier is used as part of the cache key. Make sure it's something unique\n  let identifier = \"com.schnaub.SepiaImageTransformer\"\n\n  func transform(image: UIImage) -\u003e UIImage? {\n    let filter = CIFilter(name: \"CISepiaTone\")!\n\n    let ciImage = CIImage(image: image)\n    filter.setValue(ciImage, forKey: kCIInputImageKey)\n    filter.setValue(0.5, forKey: kCIInputIntensityKey)\n\n    let context = CIContext()\n    guard let outputImage = filter.outputImage,\n          let cgImage = context.createCGImage(outputImage, from: outputImage.extent) else {\n            return image\n    }\n\n    // Return the transformed image which will be cached (or used by another transformer)\n    return UIImage(cgImage: cgImage)\n  }\n\n}\n```\n\nYou then pass this filter to MapleBacon in one of the convenience methods:\n\n```swift\nlet url = URL(string: \"…\")\nlet transformer = SepiaImageTransformer()\nimageView.setImage(with: url, transformer: transformer)\n```\n\nIf you want to apply multiple transforms to an image, you can chain your transformers:\n\n```swift\nlet chainedTransformer = SepiaImageTransformer()\n  .appending(transformer: DifferentTransformer())\n  .appending(transformer: AnotherTransformer())\n```\n\nOr if you prefer, using the custom `\u003e\u003e\u003e` operator:\n\n```swift\nlet chainedTransformer = SepiaImageTransformer() \u003e\u003e\u003e DifferentTransformer() \u003e\u003e\u003e AnotherTransformer()\n```\n\n(Keep in mind that if you are using Core Image it might not be optimal to chain individual transformers but rather create one transformer that applies multiple `CIFilter`s in one pass. See the [Core Image Programming Guide](https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html#//apple_ref/doc/uid/TP30001185).)\n\n### Caching\n\nMapleBacon will cache your images both in memory and on disk. Disk storage is automatically pruned after a week (taking into account the last access date as well) but you can control the maximum cache time yourself too:\n\n```swift\nlet oneDaySeconds: TimeInterval = 60 * 60 * 24\nMapleBacon.default.maxCacheAgeSeconds = oneDaySeconds\n```\n\n### Combine\n\nOn iOS13 and above, you can use `Combine` to fetch images from MapleBacon\n\n```swift\nMapleBacon.shared.image(with: url)\n  .receive(on: DispatchQueue.main) // Dispatch to the right queue if updating the UI\n  .sink(receiveValue: { image in\n    // Do something with your image\n  })\n  .store(in: \u0026subscriptions) // Hold on to and dispose your subscriptions\n```\n\n## Migrating from 5.x\n\nThere is a small [migration guide](https://github.com/JanGorman/MapleBacon/wiki/Migration-Guide-Version-5.x-→-6.x) in the wiki when moving from the 5.x branch to 6.x\n\n## License\n\nMapleBacon is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJanGorman%2FMapleBacon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJanGorman%2FMapleBacon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJanGorman%2FMapleBacon/lists"}