Code Monkey home page Code Monkey logo

nuke's Introduction

Advanced pure Swift framework for loading, caching, processing, displaying and preheating images. It uses latest advancements in iOS SDK and doesn't reinvent existing technologies.

Nuke is a pipeline that loads images using multiple dependencies which can be injected in runtime.

Nuke.taskWithURL(URL) { 
    let image = $0.image 
}.resume()
  1. Getting Started
  2. Usage
  3. Design
  4. Installation
  5. Requirements
  6. Contribution

Features

Loading
Caching
Decoding and Processing
  • Create and apply image filters
  • Background image decompression and scaling in a single step
  • Resize loaded images to fit displayed size
Advanced
  • Compose image filters
  • Compose image decoders
  • Customize different parts of the framework using dependency injection

Getting Started

  • Download the latest release version
  • Experiment with Nuke APIs in a Swift playground
  • Take a look at the demo project, it's easy to install with pod try Nuke command
  • Install, import Nuke and enjoy!

Usage

Zero Config

Nuke.taskWithURL(imageURL) {
    let image = $0.image
}.resume()

Adding Request Options

var request = ImageRequest(URLRequest: <#NSURLRequest#>)
request.targetSize = CGSize(width: 300.0, height: 400.0) // Set target size in pixels
request.contentMode = .AspectFill

Nuke.taskWithRequest(request) {
    let image = $0.image // Image is resized
}.resume()

Using Image Response

Nuke.taskWithRequest(request) { response in
    switch response {
    case let .Success(image, info): 
        // Use image and inspect info
    case let .Failure(error): 
        // Handle error
    }
}.resume()

Using Image Task

let task = Nuke.taskWithURL(imageURL).resume()
task.progress = { completed, total in
   // Update progress
}
let state = task.state // Track task state
task.completion { // Add multiple completions, even for completed task
    let image = $0.image
}
task.cancel()

UICollectionView

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellReuseID, forIndexPath: indexPath)

    let imageView: ImageView = <#view#>
    imageView.prepareForReuse()
    imageView.setImageWithURL(imageURL)

    return cell
}

Cancel image task as soon as the cell goes offscreen (optional):

func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
    let imageView: ImageView = <#view#>
    imageView.prepareForReuse()
}

Applying Filters

let filter1: ImageProcessing = <#filter#>
let filter2: ImageProcessing = <#filter#>
let filterComposition = ImageProcessorComposition(processors: [filter1, filter2])

var request = ImageRequest(URL: <#image_url#>)
request.processor = filterComposition

Nuke.taskWithRequest(request) {
    // Filters are applied, filtered image is stored in memory cache
    let image = $0.image
}.resume()

Composing Image Filters

let processor1: ImageProcessing = <#processor#>
let processor2: ImageProcessing = <#processor#>
let composition = ImageProcessorComposition(processors: [processor1, processor2])

Composing Image Decoders

let decoder1: ImageDecoding = <#decoder#>
let decoder2: ImageDecoding = <#decoder#>
let composition = ImageDecoderComposition(decoders: [decoder1, decoder2])

Preheating Images

let requests = [ImageRequest(URL: imageURL1), ImageRequest(URL: imageURL2)]
Nuke.startPreheatingImages(requests: requests)
Nuke.stopPreheatingImages(requests: requests)

Automate Preheating

let preheater = ImagePreheatingControllerForCollectionView(collectionView: <#collectionView#>)
preheater.delegate = self // Signals when preheat window changes

Customizing Image Manager

let dataLoader: ImageDataLoading = <#dataLoader#>
let decoder: ImageDecoding = <#decoder#>
let cache: ImageMemoryCaching = <#cache#>

let configuration = ImageManagerConfiguration(dataLoader: dataLoader, decoder: decoder, cache: cache)
ImageManager.shared = ImageManager(configuration: configuration)

Design

Protocol Description
ImageManaging A high-level API for loading images
ImageDataLoading Performs loading of image data (NSData)
ImageDecoding Converts NSData to UIImage objects
ImageProcessing Processes decoded images
ImageMemoryCaching Stores processed images into memory cache

Installation

To install Nuke add a dependency in your Podfile:

# use_frameworks!
# platform :ios / :watchos / :osx
pod "Nuke"
pod "Nuke-Alamofire-Plugin" # optional
pud "Nuke-AnimatedImage-Plugin" # optional

To install Nuke add a dependency to your Cartfile:

github "kean/Nuke"
github "kean/Nuke-Alamofire-Plugin" # optional

Import

Import installed modules in your source files

import Nuke
import NukeAlamofirePlugin
import NukeAnimatedImagePlugin
  • iOS 8.0+ / watchOS 2.0+ / OS X 10.9+
  • Xcode 7.0+, Swift 2.0+

Contribution

  • If you need help, use Stack Overflow. (Tag 'iosnuke')
  • If you found a bug, and can provide steps to reproduce it, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, branch of the develop branch and submit a pull request.

Contacts

License

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

nuke's People

Contributors

kean avatar nanoxd avatar

Watchers

James Cloos avatar  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.