swift change enum associated value code example
Example: 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)
}