Should I explicitly specify the superclass and the starting value of the enum that should contain integer values starting from 0 in Swift?
enum Foo: Int {
case Bar
case Baz
}
Thanks in advance.
Should I explicitly specify the superclass and the starting value of the enum that should contain integer values starting from 0 in Swift?
enum Foo: Int {
case Bar
case Baz
}
Thanks in advance.
That's not exactly a superclass of the enum (although it looks like), but the raw value type.
If you want to assign a value to each enum case, then yes, you have to specify the type, which can be Int
, but also String
and any other type that can be initialized with a literal.
If the raw value type is any integer type, you can omit the value associated to each case, in that case incremental values will be automatically assigned, starting from 0. Non integer types instead must have a value explicitly specified for each case.