//playground for experimenting with enums
enum pair {
case First(Int)
case Second(Int)
//add to the first case
mutating func addToFirst(amount:Int) {
switch(self){
case .First(let current):
self = .First(current + amount)
default: break
}
}
//returns the value of the enum
func getValue() -> Int {
switch(self){
case .First(let current):
return current
case .Second(let current):
return current
}
}
//computed property
var string: String {
switch(self){
case .First(let current): return String(current)
case .Second(let current): return String(current)
}
}
}
var f = pair.First(4)
f.addToFirst(4)
print(f.getValue())
f.string
//"8\n"