CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

ImageSource 4.1.2

ImageSource 4.1.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2024
SPMSupports SPM

Maintained by Andrey Yutkin, HiveHicks, Matvei Borisov.



  • By
  • Andrey Yutkin

ImageSource is an image abstraction. It is intended to represent an image that can come from many different sources.

Some examples of the sources are:

  • file system (LocalImageSource)
  • network (RemoteImageSource)
  • user's photo library (PHAssetImageSource)

It allows you to retrieve the actual bitmap in a simple and efficient way using the unified API and supports retrieval cancellation. It is also designed to be platform-independent, so you can use it both on iOS and macOS.

Installation

CocoaPods

To integrate ImageSource into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

target '<Your Target Name>' do
    pod 'ImageSource'
end

Then, run the following command:

$ pod install

Typical use cases

Displaying in UI

To present ImageSource in UIImageView, you should use extension method that comes with ImageSource/UIKit pod:

func setImage(
    fromSource: ImageSource?,
    size: CGSize? = nil,
    placeholder: UIImage? = nil,
    placeholderDeferred: Bool = false,
    adjustOptions: ((_ options: inout ImageRequestOptions) -> ())? = nil,
    resultHandler: ((ImageRequestResult<UIImage>) -> ())? = nil)
    -> ImageRequestId?

In most cases, however, you would want to just use its simplest version, passing only the first parameter:

imageView.setImage(fromSource: imageSource)

Getting image data

To get image data use ImageSource.fullResolutionImageData(completion:):

imageSource.fullResolutionImageData { data in
    try? data?.write(to: fileUrl)
}

Getting image size

To get image size use ImageSource.imageSize(completion:):

imageSource.imageSize { size in
    // do something with size
}