Advanced Localization Technique for Enums in iOS development

The Technique — Protocol based localization

What’s the technique?, using Enum’s raw representation ability and pass it as an argument in NSLocalizedString, and doing so in a protocol to conform our Enums to this protocol and get the functionality.

Notice that we are managing all the Localization functionality in one place, applying the Dry Principle.
Since the enum conforms to String, we need each case to have a string value, Localizable uses it as Raw Value

A foundation to build on

Having our Enums conform to Localizable, allows us to implement other protocols very easily, such as CaseIterable, and Identifiable, making SwiftUI development way faster and cleaner, here’s an example:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store