0

I have an enum of String type.I want to prepend a string to all cases in this particular enum.

enum MyEnum: String, CaseIterable {

    case root = "/"
    case path1 = "/path"

}

The output I want is something like

enum MyEnum: String, CaseIterable {

    case root = "myCustomString/"
    case path1 = "myCustomString/path"

}

Is it possible to modify an associated value of a case of a String enum?

func modifyEnumcases(string: String) {

/// append to each cases of an enum
}

modifyEnumcases("MyCustomString")

I tried doing it this way link

but this is not the use case I want to achieve.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Haseeb Mohamed
  • 1,459
  • 1
  • 11
  • 15
  • That is not possible. `enum` cases are immutable and are evaluated at compile time. You cannot even modify the associated value of an enum case with an associated value, since each case with a different associated value is actually a different case of the enum. – Dávid Pásztor Oct 23 '19 at 12:14
  • Too be picky, those are not associated values, they are raw values. – Joakim Danielson Oct 23 '19 at 12:15

0 Answers0