CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Oct 2017 |
| SwiftSwift Version | 4.0 |
| SPMSupports SPM | ✓ |
Maintained by kean.
Automates preheating (prefetching) of content in UITableView and UICollectionView.
This library is similar to
UITableViewDataSourcePrefetchingandUICollectionViewDataSourcePrefetchingadded in iOS 10
One way to use Preheat is to improve user experience in applications that display collections of images. Preheat allows you to detect which cells are soon going to appear on the display, and prefetch images for those cells. You can use Preheat with any image loading library, including Nuke which it was designed for.
The idea of automating preheating was inspired by Apple’s Photos framework example app.
Here is an example of how you might implement preheating in your application using Preheat and Nuke:
import Preheat
import Nuke
class PreheatDemoViewController: UICollectionViewController {
let preheater = Nuke.Preheater()
var controller: Preheat.Controller<UICollectionView>?
override func viewDidLoad() {
super.viewDidLoad()
controller = Preheat.Controller(view: collectionView!)
controller?.handler = { [weak self] addedIndexPaths, removedIndexPaths in
self?.preheat(added: addedIndexPaths, removed: removedIndexPaths)
}
}
func preheat(added: [IndexPath], removed: [IndexPath]) {
func requests(for indexPaths: [IndexPath]) -> [Request] {
return indexPaths.map { Request(url: photos[$0.row]) }
}
preheater.startPreheating(with: requests(for: added))
preheater.stopPreheating(with: requests(for: removed))
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
controller?.enabled = true
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
// When you disable preheat controller it removes all preheating
// index paths and calls its handler
controller?.enabled = false
}
}Import installed modules in your source files
import PreheatPreheat is available under the MIT license. See the LICENSE file for more info.