Etsy Hector García Peña May 5, 2022

Improving the iOS Listing Screen with Generics

Article Summary

Etsy's iOS listing screen handles 16% of all app traffic. But after a decade, its monolithic architecture was slowing everything down.

Etsy's iOS team tackled a classic legacy code problem: their most critical screen had become a performance bottleneck and developer productivity nightmare. Engineer Hector García Peña shares how they refactored using Swift generics and protocols.

Key Takeaways

Critical Insight

By abstracting cell configuration with generics, Etsy made their highest traffic screen more performant while letting engineers add features without boilerplate overhead.

The article includes actual code showing how they packed generics into a diffable data source with just a one liner.

About This Article

Problem

Etsy's listing screen had a massive switch statement that grew every time they added a new cell type. Engineers had to manually handle cell identifiers, registration, dequeuing, type casting, and view model assignment. This created a lot of repetitive, error-prone boilerplate code.

Solution

Hector García Peña's team used Swift protocols and generics to build ConfigurableCollectionViewCell and CollectionViewCellModel protocols. These abstracted cell configuration into reusable, type-safe components. Manual registration and casting became unnecessary.

Impact

Adding new cell types now takes just a single CollectionViewDefaultCellModel instantiation. Engineers get compile-time type safety that prevents them from putting the wrong view models into cells. This reduces the mental load when building features.