Enum extension

Hi, there~
What can i do for this below? I wanna to expand case options. Any solutions?

Thx for ur attention.

You cannot add extra cases to an enum. A common way to resolve this is to declare Environment [1] as a struct and then declare each case as a static property:

struct Environment: RawRepresentable {
    var rawValue: String
    static let dev = Environment(rawValue: "dev")
    static let qa = Environment(rawValue: "qa")
    static let pro = Environment(rawValue: "pro")

extension Environment {
    static let live = Environment(rawValue: "live")

You are, of course, responsible for making sure that the raw values don’t collide.

ps It’d help if you posted your code as text rather than a screen shot. That way folks can copy’n’paste it. In Markdown you can use triple backticks to denote a code block.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] I’m going to use Swift standard style for identifiers. Environment, being a type, should start with a capital.

1 Like

Hey, eskimo
Thank you for your detail answers.
I will try what you recommend.
Thank you again.