Description
Today, when an option of component api is an enum, in the configuration of the demo page of the component , en extension is always created to generate OUDSChipPickerData base on a String description.
Sometime, this Sting is hard coded, sometimes it is a wording key.
- Format this string directly form the name of the case of the enum using something like:
var formattedName: String {
let name = String(describing: self)
let withSpaces = name.replacingOccurrences(
of: "([a-z])([A-Z])",
with: "$1 $2",
options: .regularExpression
)
return withSpaces.prefix(1).uppercased() + withSpaces.dropFirst().lowercased()
}
This could be an extensions of a protocol:
protocol EnumRepresentable {
}
- Create a
OUDSChipPickerData builder based on this formatted String of each case
var chipData: OUDSChipPickerData<Self> {
OUDSChipPickerData(tag: self, layout: .text(text: self.formattedName))
}
static var chips: [OUDSChipPickerData<Self>] {
allCases.map(\.chipData)
}
In order to expose this builder to enum option, the flowing protocol can be created
protocol OptionEnumerated: CaseIterable, Hashable, EnumRepresentable {
}
Description
Today, when an option of component api is an enum, in the configuration of the demo page of the component , en extension is always created to generate
OUDSChipPickerDatabase on a String description.Sometime, this Sting is hard coded, sometimes it is a wording key.
This could be an extensions of a protocol:
OUDSChipPickerDatabuilder based on this formatted String of each caseIn order to expose this builder to enum option, the flowing protocol can be created