Latest 0.2.3
License MIT
Platforms ios 10.0
Dependencies Firebase/Storage

CI Status

ImageStore is image downloader with memory cache supporting.


To run the example project, clone the repo, and run pod install from the Example directory first.


  • Swift3.2
  • iOS10.0 or higher
  • cocoapods 1.4.0 or higher


ImageStore is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "ImageStore"

Classes, Structs, extensions


ImageStore’s config struct.


  • maxDownloadSize
    Max download size at one image. (default 2MB)

  • cacheLimit
    Cache size. (default 200MB)


  • init(maxDownloadSize: Int64, cacheLimit: Int64)


Image downloader class.


  • shared: ImageStore (static)
    Singleton shared instance.

  • config: ImageStoreConfig
    ImageStore’s config.

  • completionsByURLString: [String: [ImageStoreCompletionHandler]]
    Completion handlers dictionary indexed by source URL String.

  • downloadTaskByURLString: [String: URLSessionDownloadTask]
    Download task dictionary indexed by source URL String.

  • cache: NSCache<AnyObject, UIImage>
    Image cache.

  • queue: OperationQueue
    Image download queue.

  • session: URLSession
    Image download URLSesson.


  • reset(config: ImageStoreConfig) (class)
    Create new shared instance from ImageStoreConfig.

  • load(_ url: URL, completion: ImageStoreCompletionHandler?)
    Download image from URL, and execute CompletionHandler. If cached, only execute CompletionHandler.
    If download task has suspended, resume it.

    let url = URL(string: "")

ImageStore.shared.load(url) { [weak self] image in
self?.myImageView.image = image

ImageStore.shared.load(url) { [weak self] image in
self?.mySecondImageView.image = image

If you write like this, only one download task is create. But two completion handlers are executed.

- `suspendIfResuming(url: URL)`<br>
If ImageStore has download task with argument URL and it resuming, suspend it.<br>
You can resume it `load(url)` function.

- `cancel(url: URL)`<br>
Remove download task with argument URL.

### UIImageView+ImageStore
UIImageView extension for using ImageStore.

#### methods
- `load(_ url: URL, placeholderImage: UIImage?, shouldSetImageConditionBlock: @escaping (() -> Bool))`<br>
Second argument `shoulSetImageConditionBlock` is closure that returns a condition allow ImageView to display image.<br>
It needs for resusable view (e.g. UITableViewCell, UICollectionViewCell).<br>
When reused thats views, you may change iamge of cell's ImageView.<br>
You must call `suspendIfResuming(url: URL)` or `cancel(url: URL)` at cell's `prepareForReuse` function.<br>
But `suspendIfResuming(url: URL)` and `cancel(url: URL)` does not delete completion handler for resume or next downloading.<br>
So if executed completion handler between after `prepareForReuse` and next download image completion handler, previous image has displayed till call next download is end.<br>
Look follow example.

class MyTableViewCell: UITableViewCell {
    static let cellIdentifier = "MyTableViewCell"
    var id: String?
    var myImageView: UIImageView = UIImageView()

    override func prepareForReuse() {
        id = nil
        myImageView.image = nil

class MyListViewController: UIViewController, UITableViewDataSource {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: MyTableViewCell.cellIdentifier, for: indexPath) as? MyViewCell else { return UITableViewCell() }
        let url = urls[indexPath.row]
        let urlString = url.absoluteString = urlString
        cell.myImageView.load(url) {
            // display image if cell's id and loading image url string is match.
            return == urlString

        return cell
  • cancelLoading()
    Cancel current url loading.

  • suspendLoading()
    Suspend current url loading.


miup, [email protected]


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


  • If you found a bug, please open an issue.
  • I’m wating for your feature request, pelase open an issue.
  • I’m wating for your contribution, please create a new pull request.

Latest podspec

    "name": "ImageStore",
    "version": "0.2.3",
    "summary": "Image downloader with memory cache supporting.",
    "description": "Image downloader with memory cache supporting.nIf you want more info, look",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "miup": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.3"
    "platforms": {
        "ios": "10.0"
    "source_files": "ImageStore/Classes/**/*",
    "dependencies": {
        "Firebase/Storage": []

Pin It on Pinterest

Share This