Building Reusable Custom Views with SwiftUI
Article Summary
Max Roche from Grindr Engineering just solved one of SwiftUI's most annoying problems: why do custom components require massive initializers while Apple's native views stay clean and simple?
Building reusable SwiftUI components typically leads to bloated initializers with dozens of optional parameters. Grindr's iOS team analyzed why Apple's native components avoid this problem and built a macro to bring the same elegance to custom views.
Key Takeaways
- Apple separates required data from optional customizations using modifier chains
- Traditional approach requires boilerplate extension functions for each customization property
- @ViewConfigurable macro auto-generates modifier functions from a ViewConfiguration struct
- Keeps initializers small while enabling SwiftUI-style chaining syntax
- Now available as open source Swift Package Manager library
The @ViewConfigurable macro automatically generates SwiftUI-style modifier functions, eliminating boilerplate code while keeping custom component APIs clean and familiar.
About This Article
Grindr's custom SwiftUI components ran into trouble as the product team kept adding requests. A single button component started with 2 required parameters and ballooned to 8+ optional ones. Developers had to juggle complex initializer ordering and write out lengthy function signatures.
Max Roche's team built the @ViewConfigurable macro. It automatically generates modifier extension functions by reading a ViewConfiguration struct. This removed the need for manual boilerplate code while keeping SwiftUI's clean modifier-chaining syntax intact.
Now developers can create components with just the required parameters and customize the rest through method chains. GrindrButton("Click Me", onAction: {}).titleColor(.blue).buttonBackgroundColor(.red) works the same way Apple's native components do, without needing hand-written extension functions.