In this article, we’re going to create a generic and reusable implementation of UICollectionViewDiffableDataSource in MVVM. Hope you’re excited!

Image for post
Image for post

Short Background

UICollectionViewDiffableDataSource is a declarative API for UICollectionView data source released by Apple in iOS 13.
It sets an alternative to the old UICollectionViewDataSource — which provides us with delegate methods to determine the number of sections & cells and cell configuration based on our data set, and methods to remove and insert cells into the collection view. This approach isn’t always safe as things can often go wrong on our side; the data may not always be there at the collection view’s index path or we can miscalculate the ranges when inserting or removing cells at an index path. …

About

Eilon Krauthammer

Software engineer specializing in iOS development. I love creating and learning.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store