Automates preheating (prefetching) of content in UITableView and UICollectionView.
This library is similar to
UITableViewDataSourcePrefetchingandUICollectionViewDataSourcePrefetchingadded in iOS 10
One of the ways 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, so that you can precache 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.
Getting Started
- See Image Preheating Guide
- Check out example project for Nuke
Usage
Here is an example of how you might implement preheating in your application using Preheat and Nuke:
class PreheatDemoViewController: UICollectionViewController, PreheatControllerDelegate {
var preheatController: PreheatController!
override func viewDidLoad() {
super.viewDidLoad()
preheatController = PreheatController(view: collectionView!)
preheatController.handler = { [weak self] in
self?.preheatWindowChanged(addedIndexPaths: $0, removedIndexPaths: $1)
}
}
func preheatWindowChanged(addedIndexPaths added: [NSIndexPath], removedIndexPaths removed: [NSIndexPath]) {
func requestsForIndexPaths(indexPaths: [NSIndexPath]) -> [ImageRequest] {
return indexPaths.map { ImageRequest(photos[$0.row].URL) }
}
Nuke.startPreheatingImages(requestsForIndexPaths(added))
Nuke.stopPreheatingImages(requestsForIndexPaths(removed))
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
preheatController.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
preheatController.enabled = false
}
}Requirements
- iOS 8.0+, tvOS 9.0+
- Xcode 7.3+, Swift 2.2+
Installation
CocoaPods
To install Preheat add a dependency to your Podfile:
# source 'https://github.com/CocoaPods/Specs.git'
# use_frameworks!
# platform :ios, "8.0"
pod "Preheat"Carthage
To install Preheat add a dependency to your Cartfile:
github "kean/Preheat"
Import
Import installed modules in your source files
Contacts
License
Preheat is available under the MIT license. See the LICENSE file for more info.
