How can I do a simple index into an array using enums in Swift?
I am a C programmer trying to understand Swift. This is perplexing.
var arr: [String] = ["2.16", "4.3", "0.101"]
enum Ptr: Int {
case first = 0
case second = 1
case third = 2
}
var ix = Int(Ptr.first)
print (ix)
let e = Double (arr[ix])
`
I would expect that Ptr.first would yield a 0 integer which I could as an index into array arr.
let ix = Ptr.first.rawValueenum Ptr: Int { case first, second, third } let arr = ["2.16", "4.3", "0.101"] let ix: Ptr = .first print (ix) let e = Double(arr[ix.rawValue])