A practical approach to standardizing reusable button types in SwiftUI using a Swift enum. The pattern centralizes button definitions (add, delete, edit, done, etc.) with their SF Symbols icons, button roles, and localized titles in one place. A custom Button initializer accepts a StandardType value, automatically applying the correct role, icon, and localized string from a Swift package bundle. Custom titles and icons can still be overridden per usage. The solution integrates with Xcode 15's String Catalog for automatic localization. Known limitations include destructive button icon tinting bugs in Xcode 15.4 and constraints around applying view modifiers inside the initializer. The implementation is available in the open-source SwiftUIKit package.

5m read timeFrom danielsaidi.com
Post cover image
Table of contents
BackgroundSolutionFuture workConclusion
1 Impression