Possible Duplicate:
Objective C Equivalent of PHP’s “Variable Variables”
Today in one of my classes I learned you can access a variable by building its name from a string in Actionscript 3.0, like so:
var star1:symbol;
var star2:symbol;
var star3:symbol;
var star4:symbol;
for(i=1; i <= 4; i++)
[this "star" + i].method = something
This gets star1, then star2, then star3, then star4, and does some method with them.
Is there a way to do something like this in Objective-C?
Not quite as neat, but key-value coding does that:
EDIT: on reflection it’s unclear as a non-Actionscript user whether you intend to access properties or call methods.
You’d use
NSSelectorFromStringto convert the name of a method into a selector at runtime, then[self performSelector:...]to call the thing if it’s the latter.