Swift Tuple index using a variable as the index? Anyone know if it is possible to use a variable as the index for a Swift tuple index. I wish to select and item from a tuple usi
You can cast a tuple to a buffer only if it has an homogeneous type. But before doing so, wonder if an array can't do the job.
var tuple: (Int, Int, Int, Int) = (0,1,2,3)
withUnsafeMutablePointer(to: &tuple) { pointer in
pointer.withMemoryRebound(to: Int.self, capacity: 4) { buffer in
buffer[3] = 0
}
}
print(tuple)
result:
(0, 1, 2, 0)