Swift: Converting a string into a variable name -


i have variables incremented numbers within, such row0text, row1text, row2text, etc.

i've figured out how dynamically create string versions of variable names, once have strings, how can use them actual variable names rather strings in code?

example:

var row3text = "this value need!"  var firstpart = "row" var rownumber = 3 var secondpart = "text"  var = (firstpart+string(rownumber)+secondpart)  // below gives me concatenated string of 3 variables, i'm looking way have return value set @ top. println (together) 

once know how this, i'll able iterate through variables using loop; it's @ moment i'm unsure of how use string variable name in code.

thanks!

short answer: there no way for reason. use arrays instead.

long answer: looking way define unknown number of variables linked common format. looking define ordered set of elements of variable length. why not use array?

arrays containers allow store ordered set or list of elements , access them ordered location, you're trying do. see apple's swift array tutorial further reading.

the advantage of arrays faster, far more convenient larger sets of elements (and same smaller sets well), , come packaged ton of useful functionality. if haven't worked arrays before bit of learning curve absolutely worth it.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -