First conform to the protocol
struct MyObject: ImageCacheable {
To use the in-memory cache call:
inMemoryImage(forKey: "uniqueImageID", from: imageURL) { (image, key) in
}
If the image does not already exist, it will download the image from the specified url, and store it a a Swift Cache, but wont persist across sessions.
Alternatively you can persist images to disk and across sessions by calling:
localImage(forKey: "uniqueImageID", from: imageURL) { (image, key) in
}
To clear the cache, call either of the following functions, depending on if your using the in-memory cache or local file storage
clearInMemoryCache(success: (Bool) -> Void)
clearLocalCache(success: (Bool) -> Void)
- iOS 9.0+
- Swift 3
- Xcode 8
ImageCacheable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ImageCacheable"
ssh88, shabeershussain@gmail.com
ImageCacheable is available under the MIT license. See the LICENSE file for more info.