Swiftpack.co -  Package - kean/Preheat
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Automates prefetching of content in UITableView and UICollectionView
.package(url: "https://github.com/kean/Preheat.git", from: "4.0")

Automates preheating (prefetching) of content in UITableView and UICollectionView.

Deprecated on iOS 10. This library is similar to UITableViewDataSourcePrefetching and UICollectionViewDataSourcePrefetching added in iOS 10 which I would recommend to use instead.

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.

Getting Started


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() {

        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 {
                var request = Request(url: photos[$0.row])
                request.priority = .low
                return request
        preheater.startPreheating(with: requests(for: added))
        preheater.stopPreheating(with: requests(for: removed))

    override func viewDidAppear(animated: Bool) {

        controller?.enabled = true

    override func viewDidDisappear(animated: Bool) {

        // When you disable preheat controller it removes all preheating 
        // index paths and calls its handler
        controller?.enabled = false


  • iOS 8.0 / tvOS 9.0
  • Xcode 9
  • Swift 4



To install Preheat add a dependency to your Podfile:

# source 'https://github.com/CocoaPods/Specs.git'
# use_frameworks!
# platform :ios, "8.0"

pod "Preheat"


To install Preheat add a dependency to your Cartfile:

github "kean/Preheat"


Import installed modules in your source files

import Preheat


Preheat is available under the MIT license. See the LICENSE file for more info.


Stars: 631
Last commit: 2 weeks ago

Release Notes

Preheat 0.4.1
2 weeks ago
  • Update Swift Package description, #11
  • Support UICollectionViewCompositionalLayout, #12

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco