Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView Prefetch Data Source in iOS 10?

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

enter image description here

like image 576
khunshan Avatar asked Sep 10 '16 20:09

khunshan


People also ask

What is the difference between Uitableview and UICollectionView?

Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .

What is a UICollectionView in Swift?

An object that manages an ordered collection of data items and presents them using customizable layouts.


2 Answers

UICollectionView gains a new property this year called prefetchDataSource. Just like the existing delegate and dataSource properties, we can simply set it to some object that implements the new UICollectionViewDataSourcePrefetching protocol.

This protocol is brand new in iOS 10, and requires we implement just one new function:

public func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath])

When this function is called, we can examine the indexPaths array we're passed in to know which cells are "coming up soon" and thus which cells we should probably begin loading the data for.

For detail understanding with example refer link UICollectionViewDataSourcePrefetching

like image 175
Milap Kundalia Avatar answered Sep 30 '22 15:09

Milap Kundalia


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.

Outtles references

This for every CollectionView that i had in the storyboard. Also leave my ViewController just like that:

Class UIviewcontroller

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

like image 29
Cristian Mora Avatar answered Sep 30 '22 15:09

Cristian Mora