Reputation: 2264
Based upon this question: << Is the a ScriptEngine or eval()-like function in Swift? >> I'm assuming the following would not work in Swift:
private let BROWN_COLOUR: UIColor = UIColor.brownColor()
...
var colourName: String = "BROWN"
var colour = self[ colourName + "_COLOUR" ] as UIColor!
Correct or not?
Thank you for reading.
Upvotes: 0
Views: 647
Reputation: 92384
No, you cannot do that out of the box. You can, however, use keyed subscription to solve this. Or even easier: use a dictionary to store your values and query that.
But if the object derives from NSObject
and the instance variables are marked with @objc
, you can query these instance variables with valueForKey
.
Upvotes: 2