All Projects → JanGorman → Maplebacon

JanGorman / Maplebacon

Licence: mit
🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Maplebacon

Imageloaderswift
A lightweight and fast image loader for iOS written in Swift.
Stars: ✭ 290 (-9.94%)
Mutual labels:  xcode, cocoapods, carthage, uiimageview
Irldocumentscanner
A drop-in Objective-C ViewController that will Automatically scan a document for you you.
Stars: ✭ 172 (-46.58%)
Mutual labels:  xcode, cocoapods, carthage
Vulcan
Multi image downloader with priority in Swift
Stars: ✭ 291 (-9.63%)
Mutual labels:  image, cocoapods, carthage
Stevia
🍃 Concise Autolayout code
Stars: ✭ 3,182 (+888.2%)
Mutual labels:  xcode, cocoapods, carthage
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
Stars: ✭ 3,188 (+890.06%)
Mutual labels:  xcode, cocoapods, carthage
Donut
Donut is a library for arranging views circularly like a donut.
Stars: ✭ 141 (-56.21%)
Mutual labels:  xcode, cocoapods, carthage
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-50.93%)
Mutual labels:  xcode, cocoapods, carthage
Xcode One Dark
Atom One Dark theme for Xcode
Stars: ✭ 273 (-15.22%)
Mutual labels:  xcode, cocoapods, carthage
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (-21.43%)
Mutual labels:  xcode, cocoapods, carthage
Localize
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.
Stars: ✭ 253 (-21.43%)
Mutual labels:  xcode, cocoapods, carthage
Natrium
A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.
Stars: ✭ 131 (-59.32%)
Mutual labels:  xcode, cocoapods, carthage
Faceaware
An extension that gives UIImageView the ability to focus on faces within an image.
Stars: ✭ 3,004 (+832.92%)
Mutual labels:  cocoapods, carthage, uiimageview
Croc
Swift emoji string parsing library
Stars: ✭ 124 (-61.49%)
Mutual labels:  xcode, cocoapods, carthage
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (-8.07%)
Mutual labels:  xcode, cocoapods, carthage
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-63.04%)
Mutual labels:  xcode, cocoapods, carthage
Microfeatures Example
📦📱 Example of iOS app built using the uFeatures architecture
Stars: ✭ 112 (-65.22%)
Mutual labels:  xcode, cocoapods, carthage
Device
Light weight tool for detecting the current device and screen size written in swift.
Stars: ✭ 1,503 (+366.77%)
Mutual labels:  xcode, cocoapods, carthage
Shari
Shari is the alternative to the library of UIPickerView(drum roll) in Swift. You can select a item using UITableView.
Stars: ✭ 111 (-65.53%)
Mutual labels:  xcode, cocoapods, carthage
Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (-36.02%)
Mutual labels:  xcode, cocoapods, carthage
Audioindicatorbars
AIB indicates for your app users which audio is playing. Just like the Podcasts app.
Stars: ✭ 279 (-13.35%)
Mutual labels:  xcode, cocoapods, carthage

MapleBacon

CI codecov.io Version License Platform Carthage compatible SPM

Introduction

MapleBacon is a lightweight and fast Swift library for downloading and caching images.

Example

The folder Example contains a sample projects for you to try.

Requirements

  • Swift 5.1
  • iOS 10.0+
  • Xcode 10.2+

Installation

MapleBacon is available through CocoaPods. To install add it to your Podfile:

pod "MapleBacon"

Carthage

github "JanGorman/MapleBacon"

and Swift Package Manager.

Usage

UIImageView

The most basic usage is via an extension on UIImageView. You pass it URL:

import MapleBacon

private var imageView: UIImageView!

func someFunc() {
  let url = URL(string: "…")
  imageView.setImage(with: url)
}

If you want to add a placeholder while the image is downloading you specify that like this:

func someFunc() {
  let url = URL(string: "…")
  imageView.setImage(with: url, placeholder: UIImage(named: "placeholder"))
}

If 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:

func someFunc() {
  let url = URL(string: "…")
  imageView.setImage(with: url, displayOptions: .downsampled)
}

Image Transformers

MapleBacon 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:

private class SepiaImageTransformer: ImageTransforming {

  // The identifier is used as part of the cache key. Make sure it's something unique
  let identifier = "com.schnaub.SepiaImageTransformer"

  func transform(image: UIImage) -> UIImage? {
    let filter = CIFilter(name: "CISepiaTone")!

    let ciImage = CIImage(image: image)
    filter.setValue(ciImage, forKey: kCIInputImageKey)
    filter.setValue(0.5, forKey: kCIInputIntensityKey)

    let context = CIContext()
    guard let outputImage = filter.outputImage,
          let cgImage = context.createCGImage(outputImage, from: outputImage.extent) else {
            return image
    }

    // Return the transformed image which will be cached (or used by another transformer)
    return UIImage(cgImage: cgImage)
  }

}

You then pass this filter to MapleBacon in one of the convenience methods:

let url = URL(string: "…")
let transformer = SepiaImageTransformer()
imageView.setImage(with: url, transformer: transformer)

If you want to apply multiple transforms to an image, you can chain your transformers:

let chainedTransformer = SepiaImageTransformer()
  .appending(transformer: DifferentTransformer())
  .appending(transformer: AnotherTransformer())

Or if you prefer, using the custom >>> operator:

let chainedTransformer = SepiaImageTransformer() >>> DifferentTransformer() >>> AnotherTransformer()

(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 CIFilters in one pass. See the Core Image Programming Guide.)

Caching

MapleBacon 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:

let oneDaySeconds: TimeInterval = 60 * 60 * 24
MapleBacon.default.maxCacheAgeSeconds = oneDaySeconds

Combine

On iOS13 and above, you can use Combine to fetch images from MapleBacon

MapleBacon.shared.image(with: url)
  .receive(on: DispatchQueue.main) // Dispatch to the right queue if updating the UI
  .sink(receiveValue: { image in
    // Do something with your image
  })
  .store(in: &subscriptions) // Hold on to and dispose your subscriptions

Migrating from 5.x

There is a small migration guide in the wiki when moving from the 5.x branch to 6.x

License

MapleBacon is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].