GDImage is a Swift library providing background image-loading capabilities.
- Asnychronous image downloading
- Two-layer caching: memory and disk
- UIImage extensions offered
- Support for download cancellation
- Support for jpeg and png images tested
- iOS 9.0+
- Xcode 8.0+
- Swift 3.0+
CocoaPods 1.1.0+ is required.
To integrate GDImage into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'GDImage', :git => 'https://github.com/spinach/GDImage', :tag => '1.0.6'
end
Then, run the following command:
$ pod install
To integrate GDImage into your Xcode project using Carthage, specify it in your Cartfile
:
github "spinach/GDImage"
Run carthage update
to build the framework and drag the built GDImage.framework
into your Xcode project.
The simplest way to use GDImage is using UIImageView extension
import GDImage
imageView.setImage(withLink: "https://s3.amazonaws.com/dummy-images-guy/algolia-logo.jpg")
GDImage will download the image asynchronously, put it in the memory cache and disk cache, and then display it in imageView
.
You can quickly try out the library by cloning this repo and opening GDImage.xcworkspace
. Build the GDImage
target, then run the Demo
target.
func setImage(withUrl: URL)
func setImage(withLink: String)
func cancelImageDownload()
GDImage offers more customisation.
import GDImage
let gdImage = GDImage()
gdImage.setImage(ofImageView: imageView, withUrl: url)
The constructor lets you customise whether to use caching or not, the contentMode of the UIImageView and the activityIndicatorStyle shown while loading the image.
GDImage(useCacheStore:Bool = true, contentMode: UIViewContentMode = .scaleAspectFit, activityIndicatorStyle: UIActivityIndicatorViewStyle = .gray)
The methods for GDImage are similar to the ones of extensions of UIImageView
func setImage(ofImageView: UIImageView, withUrl: URL)
func setImage(ofImageView: UIImageView, withLink: String)
func cancelDownload(ofImageView: UIImageView)
If you wish to do some task at the completion of an image download, or do error handling, you can use the optional argument completionHandler
like this:
imageView.setImage(withUrl: url) { (image, error) in
// use error to do error handling
// use image to do something with the image
}
- Create workspace containing Demo and Library
- Write to Store Asynchronously
- Manutally test with more image formats
- Add default ActivityIndicator while loading image
- Support for Carthage
- More cleanup, especially print statements
- Handle error cases (when image cannot be found). Can offer an errorHandler in the method
- Provide onCompleteHandler
- Write some basic UTs
- Write more in-depth UTs
- Improve the Demo project
- Prefetch image capabilities
- Provide placeholer image capabilities
- Submit public pod
GDImage is released under the MIT license. See LICENSE for details.