What is the purpose of prefetchDataSources
introduced in iOS 10?
I just ran a project in XCode 8 GM Seed and started getting errors:
MessagesExtension[17902:1238603] *** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/UICollectionView.m:2161
i was had the same problem after updating from xcode 8 to 8.1. I could solve it deleting the (Outlets reference) from the main.storyboard.
This for every CollectionView that i had in the storyboard. Also leave my ViewController just like that:
Class (YourViewControllerName): (YourViewControllerType) , UICollectionViewDataSource, UICollectionViewDelegate{
}
Then i can build and run my App
However, if you need use (UICollectionViewDataSourcePrefetching) i recomment you that delete the current UICollectionView, later create a new UICollectioView. just like that you can use UICollectionViewDataSourcePrefetching after updateing xcode or swift
Implement protocol "UICollectionViewDataSourcePrefetching" in you ViewController as
class ViewController: UIViewController , UICollectionViewDataSourcePrefetching {
Set following delegates to your collection view in storyboard (see the attached image) or programmatically
In ViewController's viewDidLoad method
collectionView.delegate = self
collectionView.dataSource = self
collectionView.prefetchDataSource = self
Refer this example - https://github.com/Be-With-Viresh/CollectionViewWithPrefetch
Add protocol "UICollectionViewDataSourcePrefetching" And then use below functions.
collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath])
collectionView(_ collectionView: UICollectionView, cancelPrefetchingForItemsAt indexPaths: [IndexPath])
For detail refer Link: https://adoptioncurve.net/archives/2016/06/collection-view-updates-in-ios10/
This protocol is brand new in iOS 10, and requires we implement just one new function:
For detail understanding with example refer link UICollectionViewDataSourcePrefetching