• This repository has been archived on 06/Feb/2023
  • Stars
    star
    629
  • Rank 71,454 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automates prefetching of content in UITableView and UICollectionView

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

Usage

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

Requirements

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

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

import Preheat

License

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

More Repositories

1

Nuke

Image loading system
Swift
8,112
star
2

Pulse

Network logger for Apple platforms
Swift
6,307
star
3

DFImageManager

Image loading, processing, caching and preheating
Objective-C
1,180
star
4

Get

Web API client built using async/await
Swift
941
star
5

PulsePro

A macOS app for viewing logs from Pulse
Swift
482
star
6

Align

Intuitive and powerful Auto Layout library
Swift
350
star
7

Future

Streamlined Future<Value, Error> implementation
Swift
317
star
8

FetchImage

Makes it easy to download images using Nuke and display them in SwiftUI apps
Swift
212
star
9

Regex

Open source regex engine
Swift
211
star
10

Arranged

Open source replacement of UIStackView for iOS 8 (100% layouts supported)
Swift
208
star
11

VPN

Sample custom VPN client/server in Swift
Swift
182
star
12

Formatting

Swift
179
star
13

DFCache

Composite LRU cache with fast metadata using UNIX extended file attributes
Objective-C
162
star
14

RxNuke

RxSwift extensions for Nuke
Swift
148
star
15

CreateAPI

Delightful code generator for OpenAPI specs
Swift
142
star
16

SwiftSQL

Swift API for SQLite
Swift
131
star
17

ThreeColumnNavigation

A minimal example of three-column navigation for iPad and macOS using SwiftUI
Swift
127
star
18

Stacks

A micro UIStackView convenience API inspired by SwiftUI
Swift
73
star
19

Nuke-FLAnimatedImage-Plugin

FLAnimatedImage plugin for Nuke
Swift
53
star
20

RxUI

Auto-binding for RxSwift inspired by SwiftUI
Swift
45
star
21

Nuke-Alamofire-Plugin

Alamofire plugin for Nuke
Swift
40
star
22

NukeDemo

Nuke Demo
Swift
34
star
23

DFJPEGTurbo

Objective-C libjpeg-turbo wrapper
C
33
star
24

ImagePublisher

Combine publishers for Nuke
Swift
25
star
25

NukeUI

Lazy image loading for Apple platforms: SwiftUI, UIKit, AppKit
Swift
19
star
26

articles

Articles for kean.github.io
19
star
27

URLQueryEncoder

URL query encoder with support for all OpenAPI serialization options
Swift
17
star
28

NukeBuilder

A fun and convenient way to use Nuke
Swift
14
star
29

ScrollViewPrefetcher

Prefetching for SwiftUI
Swift
14
star
30

PulseLogHandler

SwiftLog Extension for Pulse
Swift
12
star
31

HTTPHeaders

Parsing Simple HTTP Headers
Swift
11
star
32

OctoKit

GitHub API client built with Fuse
Swift
8
star
33

PulseApps

Base Pulse macOS and iOS apps and a few demo projects
Swift
7
star
34

kean

1
star