swift how to set enum code example
Example 1: swift change enum value
enum SimpleEnum{
case big(String)
case small(String)
case same(String)
mutating func adjust() {
switch self{
case let .big(name):
self = .big(name + "not")
case let .small(name):
self = .small(name + "not")
case let .same(name):
self = .same(name + "not")
}
}
}
var test = SimpleEnum.big("initial")
test.adjust()
switch test {
case let .big(name):
print(name)
case let .small(name):
print(name)
case let .same(name):
print(name)
}
Example 2: swift enum
enum Planet {
case mercury, venus, earth, mars, jupiter, saturn, uranus, neptune
}