Code Monkey home page Code Monkey logo

tangerine's Introduction

Tangerine 🍊

Tangerine is a Swift µframework for fetching Images.

Installation

Swift Package Manager

Swift Package Manager is integrated within Xcode 11, so using Tangerine in your project is a piece of cake:

  1. File → Swift Packages → Add Package Dependency...
  2. Paste the repository URL (https://github.com/RuiAAPeres/Tangerine) and click Next.
  3. For Rules, either select version, branch or commit.
  4. Select the Target where you would like to add Tangerine. The correct one should be already selected for you.
  5. Click Finish.

Manual Installation

Drag the Tangerine.swift file into your project. 🍊

Usage

Typically a view should have a single ImageFetcher, and as such it’s not possible for one to fetch different images with only one instance of a ImageFetcher. From a code point of view:

let tangerines = URL(string: "https://www.strongertogether.coop/sites/default/files/Tangerines.jpg")!
let fetcher = ImageFetcher(urL: tangerines)
let example = ExampleView(fetcher: fetcher)
struct ExampleView: View {
  @ObservedObject var fetcher: ImageFetcher
  
  init(fetcher: ImageFetcher) {
    self.fetcher = fetcher
  }
  
  var body: some View {
    VStack {
      fetcher.image.map {
        Image(uiImage: $0)
          .resizable()
          .aspectRatio(contentMode: .fit)
      }
    }
    .onAppear(perform: fetcher.refresh)
  }
}

The actual HTTP request is done not when the ImageFetcher is created, but when the refresh method is called.

Tangerine also supports caching via NSCache. You can either supply yours, or use the default one.

tangerine's People

Contributors

ruiaaperes avatar mluisbrown avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.