Latest 0.1.4
Homepage https://github.com/lo-fo/ASAPImage
License MIT
Platforms ios 10.0
Authors

A library providing asynchronous image downloading utilities.

ASAPImageView

ASAPImageView is a subclass of UIImageView.

It handles fetching an image from an URL then asynchronously setting it as its image property.

Basic usage

import ASAPImage

let url: URL!

let asapImageView = ASAPImageView()
asapImageView.load(imageAt: url)

While a request is ongoing, any subsequent modification of the image, wether through a new call to load(imageAt:) or by setting the image property directly, will result in the cancellation of the ‘old’ request.

Request cancellation

The cancel() method allows you to cancel the ongoing request.

asapImageView.load(imageAt: url)
asapImageView.cancel()

Request completion

load(imageAt:) accepts as an optional argument a callback to notify your code of the request’s completion.
The callback takes as an argument a Result<Void> type, which is an enum with .success and .failure(Error) cases.

asapImageView.load(imageAt: url) { result in
    switch result {
    case .success:
         /* your logic */
    case .failure(let error):
         /* your logic */
    }
}

Cancelling a request will result with a .failure(Error) completion.

ASAPImageLoader

For pure image downloading you can use the ASAPImageLoader singleton.

In the same fashion as ASAPImageView, it provides a load(imageAt:completion:) method. This time the completion handler is obligatory and its argument is of type Result<Image>.

ASAPImageLoader.shared.load(imageAt: url) { result in
    switch result {
    case .success(let image):
         /* your logic */
    case .failure(let error):
         /* your logic */
    }
}

Request cancellation

If you want to cancel a request you can use the CancellationToken returned by the load(imageAt:completion:) method.

let token = ASAPImageLoader.shared.load(imageAt: url) { /* your logic */ }
token.cancel()

Installation with Cocoapods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

pod 'ASAPImage'

If you are using Swift, be sure to add use_frameworks!

use_frameworks!

Latest podspec

{
    "name": "ASAPImage",
    "version": "0.1.4",
    "summary": "Asynchronous image downloading utilities",
    "description": "A library providing asynchronous image downloading utilities.",
    "homepage": "https://github.com/lo-fo/ASAPImage",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Louis Fournier": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lo-fo/ASAPImage.git",
        "tag": "0.1.4"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": [
        "ASAPImage/ASAPImage*.swift",
        "ASAPImage/Async/*.swift",
        "ASAPImage/Utilities/*.swift"
    ]
}

Pin It on Pinterest

Share This