Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kean/Preheat
Automates prefetching of content in UITableView and UICollectionView
https://github.com/kean/Preheat
Last synced: about 1 month ago
JSON representation
Automates prefetching of content in UITableView and UICollectionView
- Host: GitHub
- URL: https://github.com/kean/Preheat
- Owner: kean
- License: mit
- Archived: true
- Created: 2016-03-24T17:19:56.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2023-02-05T23:48:15.000Z (almost 2 years ago)
- Last Synced: 2024-05-08T22:41:29.348Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 41 KB
- Stars: 630
- Watchers: 18
- Forks: 24
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Preheat - Automates prefetching of content in UITableView and UICollectionView (UI / Table View / Collection View)
- awesome-ios-star - Preheat - Automates prefetching of content in UITableView and UICollectionView (UI / Table View / Collection View)
README
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](https://github.com/kean/Nuke) which it was designed for.
The idea of automating preheating was inspired by Apple’s Photos framework [example app](https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html).
## Getting Started
- See [Image Preheating Guide](https://kean.github.io/blog/image-preheating)
- Check out example project for [Nuke](https://github.com/kean/Nuke)## Usage
Here is an example of how you might implement preheating in your application using **Preheat** and **Nuke**:
```swift
import Preheat
import Nukeclass PreheatDemoViewController: UICollectionViewController {
let preheater = Nuke.Preheater()
var controller: Preheat.Controller?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### [CocoaPods](http://cocoapods.org)
To install Preheat add a dependency to your Podfile:
```ruby
# source 'https://github.com/CocoaPods/Specs.git'
# use_frameworks!
# platform :ios, "8.0"pod "Preheat"
```### [Carthage](https://github.com/Carthage/Carthage)
To install Preheat add a dependency to your Cartfile:
```
github "kean/Preheat"
```### Import
Import installed modules in your source files
```swift
import Preheat
```## License
Preheat is available under the MIT license. See the LICENSE file for more info.