Skip to content

Quick Unsplash object that caches random images from a collection in batches.

License

Notifications You must be signed in to change notification settings

AndresCanella/UnsplashImageCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

UnsplashImageCache

Will batch download images and save into a chache every time that preCache is called. randomElement() will provide a one of the random cached images and will rotate which is shown to always shot the image that has not been shown since the longest.

This currently has limited functionallity, what it does it does well. If you're interested in extending this functionality, I'll happily integrate any good new feature you come up with.

Installation

Copy UnsplashImageCache.swift to your project. Use cocoa pods to install RxSwift and RealmSwift.

Ussage

Initialize object with your Unsplash info and target collections string array.

let u = UnsplashImageCache(clientId:<your Unsplash client id>, collections:<colection ids>, debugLogging:true, maxUnusedCount:10)

Precache images:

u.preCache(imageCount:3)

Get image item:

let e = u.randomElement()
e.image

Optionally, subscribe to get system updates:

u.status.subscribe(onNext: { status in
    switch status {
    case .requesting(let path):
        print("requesting: \(path)")
    case .error(let description):
        print("error: \(description)")
    case .requestAPISuccess:
        print("requestSuccess")
    case .requestImagesDone(let succeeded):
        print("requestImagesDone: \(succeeded)")
    case .skipFetchTargetUnseenReached:
        print("skipFetchTargetUnseenReached")
    }
})

Or request list of cached items:

u.debugListDbElements()

Features

  • Rx Based
  • Lazy load images bit by bit
  • download and cache images
  • background threaded
  • Always shows first seen image (oldest)

Requirements

Install these pods

  • RxSwift
  • RealmSwift

About

Quick Unsplash object that caches random images from a collection in batches.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages