-
Notifications
You must be signed in to change notification settings - Fork 2
combine enum's the RawValue type define and it's protocol as the one #6
Copy link
Copy link
Open
Labels
Code Designbetter architecture to discussbetter architecture to discuss
Description
public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
var prettyRawValue: RawValue { get }
}
public extension PrettyRawRepresentable {
var prettyRawValue: String {
let paths = String(reflecting: self).split(separator: ".").dropFirst()
if String(paths.last ?? "") != rawValue {
return rawValue
}
return paths.joined(separator: "_")
}
}As we already defined
PrettyRawRepresentable's RawValue == String,
but enum cannot write as blow, why?enum Home: PrettyRawRepresentable { case setting } let str = Home.seeting.prettyRawValue // Home_setting
current
enum Home: String, PrettyRawRepresentable {
case setting
}
let str = Home.seeting.prettyRawValue // Home_settingwants
enum Home: XXX {
case setting
}
let str = Home.seeting.prettyRawValue // Home_settingXXXcan be a protocol or a struct, but should better as a subprotocol of RawRepresentableXXXmethod already be achieved (no more code as the blow)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Code Designbetter architecture to discussbetter architecture to discuss