Reputation: 63
I would like to refer to a variable in swift using a combination of a string and another variable. In php I would often do the following:
$i = 1
${'variable' . $i} = 'test'
Which is the same as
$variable1 = 'test'
How is this done in Swift?
Upvotes: 4
Views: 1414
Reputation: 45220
You can't. Unlike PHP, Swift is not an interpreted language. As of version 1.1 it doesn't support almost any dynamism (which is a cost for being safe and performant).
Upvotes: 5