Wise Pattogató Bence

How Wise Implements Diffable DataSource for Heterogeneous Items in iOS

Original post Implementing Diffable DataSource for Heterogeneous Items in iOS

Article Summary

Pattogató Bence from Wise Engineering tackles a problem every iOS dev faces: animating heterogeneous items in collection views without the usual headaches. His solution? A clever enum wrapper that makes UICollectionViewDiffableDataSource work with mixed content types.

The Wise engineering team needed to build their Insights feature with complex, multi-section collection views containing different item types (monthly summaries, legends, spending categories). Traditional approaches meant manual batch updates or CoreData dependencies. This article shows how they leveraged DiffableDataSource for cleaner, animated updates.

Key Takeaways

Critical Insight

By wrapping different item types in an enum, you can use DiffableDataSource for automatic animated updates without manual batch operations or CoreData dependencies.

Continue reading

What This Article Covers

Problem

UICollectionViews don't have built-in diffing, so developers have to pick between writing manual performBatchUpdates calls, using Swift 5.1's ordered collection diffing, or adding CoreData just to animate insert, delete, reload, and move operations.

Solution

Bence Pattogatò wraps different item types like Day and Hour in value-associated enums and subclasses UICollectionViewDiffableDataSource to automatically find differences between snapshots and animate updates. No manual work needed.

Impact

The Wise Insights feature shows three item types (months, legend, spending categories) across multiple sections and can refresh specific parts without reloading everything. This removes the need for CoreData or batch update code while keeping the presenter pattern clean and organized.

The article includes a complete demo weather app showing how tapping a day reveals hourly forecasts with smooth animations and minimal view controller code.

This page summarizes “Implementing Diffable DataSource for Heterogeneous Items in iOS” by Wise, published Sep 15, 2021. All credit for the original work goes to the authors.

Read the original on medium.com (opens in new tab)

AI tools for iOS

Browse all AI tools →