SunWuKong 0.0.2

SunWuKong 0.0.2

Maintained by Sorawit.



 
Depends on:
Firebase/Core>= 0
Firebase/Storage>= 0
 

SunWuKong 0.0.2

  • By
  • WuKong

SunWuKong

SunWuKong is a pure-Swift library for downloading and caching images from the Firebase Storage and URL. This project is heavily inspired by the popular FirebaseStorageCahce and MapleBacon .

Version License Platform

Requirements

Swift 4

iOS 9.0+

Xcode 9+

This project assumes that you have already setup Firebase for iOS.

Installation

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

pod 'SunWuKong'

Usage

UIImageView

  • With Storage Reference
let ref: StorageReference = ....
imageView.wk_setImage(with: ref)
  • With placeholder, progress and completion handler
func setImageWithStorageReference() {
  let ref: StorageReference =  ....
  imageView.wk_setImage(with: ref, placeholder: UIImage(named: "placeholder"), progress: { received, total in
    // Report progress
  }, completion: { [weak self] image in
    // Do something else with the image
  })

}
  • With URL
let url: URL = ....
imageView.wk_setImage(with: url)
  • With placeholder, progress and completion handler
func setImageWithURL() {
  let url: URL = ....
  imageView.wk_setImage(with: url, placeholder: UIImage(named: "placeholder"), progress: { received, total in
    // Report progress
  }, completion: { [weak self] image in
    // Do something else with the image
  })

}

Use the default shared cache

let ref: StorageReference = ...
SunWuKong.shared.image(with: ref) { [weak self] image in
  // do something with your image
}

Create custom storage caches

let oneDaySeconds: TimeInterval = 60 * 60 * 24
let oneDayCache = DiskCache(name: "customCache", cacheDuration: oneDaySeconds)
let wukongCache = SunWuKong(cache: oneDayCache)

Cleaning/pruning the cache

In the didFinishLaunchingWithOptions of your AppDelegate, you should call the prune() method of your disk caches to remove any old files:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    SunWuKong.shared.prune()
    return true
}

Author

WuKong, [email protected]

License

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