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 .
Swift 4
iOS 9.0+
Xcode 9+
This project assumes that you have already setup Firebase for iOS.
SunWuKong is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SunWuKong'
- 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
})
}
let ref: StorageReference = ...
SunWuKong.default.image(with: ref) { [weak self] image in
// do something with your image
}
let oneDaySeconds: TimeInterval = 60 * 60 * 24
let oneDayCache = DiskCache(name: "customCache", cacheDuration: oneDaySeconds)
let wukongCache = SunWuKong(cache: oneDayCache)
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.default.prune()
return true
}
WuKong, sorawit.tr@gmail.com
SunWuKong is available under the MIT license. See the LICENSE file for more info.