AlamofireImage Documentation

repository·master·Indexed 26 days ago

https://github.com/alamofire/alamofireimage

An image component library built for Alamofire that provides advanced image handling capabilities, including async remote downloads, auto-purging in-memory caching, and image processing extensions. Key features include Image Response Serializers, UIImage extensions for scaling and rounding, custom ImageFilter protocols, and UIImageView extensions for asynchronous loading with placeholders and transitions.

Tokens
4.5K
Snippets
15
Records
25
Agent score
86%

What's inside AlamofireImage

  1. AlamofireImage Overview and Features

    master

    AlamofireImage is an image component library for Alamofire.

    Key Features:

    • Image Response Serializers
    • UIImage Extensions (Inflation, Scaling, Rounding, CoreImage)
    • Single and Multi-Pass Image Filters
    • Auto-Purging In-Memory Image Cache
    • Prioritized Queue Order Image Downloading
    • Authentication with URLCredential
    • UIImageView Async Remote Downloads with Placeholders
    • UIImageView Filters and Transitions
  2. Install AlamofireImage manually as an Embedded Framework

    master

    If you are not using a dependency manager, follow these steps to integrate AlamofireImage manually:

    1. Initialize git if your project is not already a git repository: git init
    2. Add AlamofireImage as a git submodule: git submodule add https://github.com/Alamofire/AlamofireImage.git
    3. Drag the AlamofireImage.xcodeproj from the new folder into your application's Xcode Project Navigator.
    4. Verify the deployment target of AlamofireImage.xcodeproj matches your application target.
    5. In your application's target settings, go to the General panel.
    6. Under Embedded Binaries, click the + button.
    7. Select the AlamofireImage.framework from the Products folder (select the top one for iOS and the bottom one for macOS).

    AlamofireImage will be automatically added as a target dependency, linked framework, and embedded framework.

    $ git init
    $ git submodule add https://github.com/Alamofire/AlamofireImage.git
  3. Migrate from AlamofireImage 3.x to 4.0

    master

    AlamofireImage 4.0 is a major release that introduces breaking API changes to align with Alamofire 5 and adopt more Swifty conventions.

    Requirements

    • iOS: 10.0+
    • macOS: 10.12+
    • tvOS: 10.0+
    • watchOS: 3.0+
    • Xcode: 10.2+
    • Swift: 5+

    Key Changes

    • API Prefixing: The af_ prefix for UIImage, UIImageView, and UIButton extensions has been replaced with an af property.
    • ImageDownloader Refactor: The sessionManager property is now session to align with Alamofire 5.
    • Cancellation Behavior: Cancelling an image download now fully cancels the request, even if it has already started, to prevent background processing and threading issues.
  4. Migrate to AlamofireImage 2.0

    master

    AlamofireImage 2.0 is a major release that introduces breaking changes to align with Alamofire 3.0.

    Requirements:

    • iOS 8+
    • Mac OS X 10.9+
    • watchOS 2.0
    • Xcode 7
    • Swift 2.0

    Key Benefits:

    • Compatibility with Alamofire 3.0.
    • Uses generic Response types for all Request completion closures.
    • Improved request cancellation via RequestReceipt for optimized performance in table and collection views.
  5. Install AlamofireImage via Swift Package Manager

    master

    To add AlamofireImage as a dependency in your Package.swift file, add it to the dependencies array:

    dependencies: [
        .package(url: "https://github.com/Alamofire/AlamofireImage.git", .upToNextMajor(from: "4.4.0"))
    ]
  6. Migrate from AlamofireImage 2.x to 3.0

    master

    AlamofireImage 3.0 is a major release that introduces breaking API changes to comply with Swift 3 API Design Guidelines and Alamofire 4 compatibility.

    Requirements

    • iOS: 8.0+
    • macOS: 10.10+
    • tvOS: 9.0+
    • watchOS: 2.0+
    • Xcode: 8.0+
    • Swift: 3.0+

    Note: If you require Swift 2.2 or 2.3, use the latest tagged 2.x release instead.

    Key Improvements

    • Full compatibility with Alamofire 4.
    • Complete Swift 3 compatibility following official API Design Guidelines.
    • New error system using the AFIError type.
  7. Update Request extension responseImage signature

    master

    The responseImage method in the Request extension has been updated to match Alamofire 3.0's ResponseSerializer changes. The completionHandler now uses the type Response<Image, NSError> -> Void. While the underlying serialization functionality remains the same, the closure signature must be updated in your code.

    public func responseImage(
        imageScale: CGFloat = Request.imageScale,
        inflateResponseImage: Bool = true,
        completionHandler: Response<Image, NSError> -> Void) 
        -> Self
  8. Update Image Cache API usage

    master

    The ImageCache methods have been renamed for better readability and adherence to Swift 3 guidelines.

    • Getting an image: Use image(withIdentifier:) instead of imageWithIdentifier(_:).
    • Adding an image: Use add(_:withIdentifier:) or add(_:for:withIdentifier:) instead of addImage(_:withIdentifier:) or addImage(_:forRequest:withAdditionalIdentifier:).
    • Removing an image: Use removeImage(withIdentifier:) or removeImage(for:withIdentifier:) instead of removeImageWithIdentifier(_:) or removeImageForRequest(_:withAdditionalIdentifier:).