2. What is it?
“A data-driven UICollectionView framework for building fast and flexible lists.”
Built and open sourced by the Instagram engineering team
Helps us creating fast and flexible UICollectionViews
Provides cool features like animations and linear complexity diff calculations
Installed via cocoapods
“Automatically identifies changes within a collection and updates the appropriate rows with animation”
It is structured to handle multiple sections with different data and UI
3. Why IGListKit?
1.Better architectures
IGListKit reduces the chance of having “massive view controllers” by
dividing responsibilities into multiple layers: the view controller, list
adapter, section controller, and the cell.
4. Why IGListKit?
2. Diffing
UICollectionView can handle all types of updates (deletes, reloads, moves,
and inserts), but performing those updates without crashing can be a
little tricky.
6. Implementing IGListKit
1. Install it via cocoapods/Carthage
2. Add a IGListCollectionView object to your ViewController
3. Add a IGListAdapter object (handles row and section updates)
{
adapter.collectionView = collectionView
adapter.dataSource = self (VC)
}
7. Implementing IGListKit
4. The adapter must conform to the IGListAdapterDataSource
protocol, so:
extension ViewController: IGListAdapterDataSource {
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable]
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController
func emptyView(for listAdapter: IGListAdapter) -> UIView?
}
8. Implementing IGListKit
5. The Section Controller
A class that inherits IGListSectionController
It needs to conform the IGListSectionType protocol:
func numberOfItems() -> Int
func sizeForItemAtIndex(index: Int) -> CGSize
func cellForItemAtIndex(index: Int) -> UICollectionViewCell
func didUpdateToObject(object: AnyObject)
func didSelectItemAtIndex(index: Int)
9. is performUpdatesAnimated always necessary
when data changes?
“For clarification, IGListKit doesn't observe changes in your data source. That'd require us use some KVO or ReactiveCocoa mechanism. It's
totally doable, but we don't want to dictate how your stuff gets updated.” Ryan Nystrom
So, “whenever your data changes you need to call performUpdatesAnimated:completion: to update the actual view state.”
{
adapter.performUpdatesAnimated: completion:
}