Valley, a file downloader written in Swift 4 for iOS
- Images are downloaded asynchronously.
- LRU concept to cache management
- Allows to configure cache size.
- Has extension for UIImageView
- Provides closure properties manipulation and error handling.
TODO List
- In Memory Cache
- Disk Storage Cache
- Improve cache item size
- New extensions (e.g. WKWebView)
- Travis integration
- SSL Pinning option
Setup
Setup with CocoaPods (iOS 10+)
If you are using CocoaPods add this text to your Podfile and run pod install
.
use_frameworks!
target 'Your target name'
pod 'Valley'
Usage
-
Add
import Valley
to your code -
From your UIImageView instance, you can just:
imageView.valleyImage(url: "https://yourwebseite.com/img.jpeg")
- To download other kind of files for example:
// JSON
ValleyFile<[[String: Any]]>.request(url: "https://yourwebsite.com/data.json") { (json) in }
// Data to fill a webview with a PDF
ValleyFile<Data>.request(url: "https://yourwebsite.com/myfile.pdf") { (data) in }
Canceling download
To manually cancel the download, call:
let task = imageView.valleyImage(url: "https://yourwebseite.com/img.jpeg")
task.cancel()
Supply a placeholder image
You can supply an error image that will be used if an error occurs during image download.
imageView.valleyImage(url: "https://yourwebseite.com/img.jpeg", placeholder: image)
Cache
The following method clear all items from cache
Valley.cache.clearCache()
Settings
Use Valley.setup(capacity: Int)
to define a capacity in bytes to cache.
Demo app
The demo iOS app shows how to load images in a collection view with Valley and also load files like JSON.
Alternative solutions
Here is the list of other image download libraries for Swift.
- cbot/Vincent
- daltoniam/Skeets
- Haneke/HanekeSwift
- hirohisa/ImageLoaderSwift
- natelyman/SwiftImageLoader
- onevcat/Kingfisher
- zalando/MapleBacon
- evgenyneu/moa
- kean/Nuke
License
Valley is released under the MIT License.
Feedback is welcome
If you notice any issue, got stuck or just want to chat feel free to create an issue. I will be happy to help you.