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
- Replaced monolithic view with UICollectionView to defer layout computations
- Built generic cell configuration using Swift protocols and associated types
- Eliminated repetitive switch statements that grew with every new cell type
- Achieved compile time type safety between cells and view models
- New sections now plug in without manual registration or casting
By abstracting cell configuration with generics, Etsy made their highest traffic screen more performant while letting engineers add features without boilerplate overhead.
About This Article
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.
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.
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.