lundi 28 août 2017

Get the value of a Swift variable from a constructed name

I am stuck at a problem which i am trying to figure out in Swift 4.

Let say, i have the below variables

let var1 = "One"
let var2 = "Two"
let var3 = "Three"

var counter = 1

// Loop Start

let currentVariable = "var" + "\(counter)"

//Fetch the value of variable stored under currentVariable

counter += 1

//Loop end

I am trying to get the value based on variable name stored under currentVariable.





Aucun commentaire:

Enregistrer un commentaire