可能重复:
Objective C Equivalent of PHP’s “Variable Variables”动态构造变量名
今天在我的班级之一,我了解到,你可以通过从ActionScript中的字符串构建的名称访问变量3.0,像这样:
var star1:symbol;
var star2:symbol;
var star3:symbol;
var star4:symbol;
for(i=1; i <= 4; i++)
[this "star" + i].method = something
这得到star1
,然后star2
,然后star3
,然后star4
,并用它们做一些方法。
有没有办法在Objective-C中做这样的事情?
难道你的意思是这个[“明星” + 1]。方法[ObjC相当于PHP的的“的 –
可能重复变量变量“](http://stackoverflow.com/questions/2283374/objective-c-equivalent-of-phps-variable-variables),[基于int计数创建多个变量](http://stackoverflow.com/questions/2231783/create-multiple-variables-based-on-an-int-count /),[Syntax help:variable as object name](http://stackoverflow.com/questions/7940809/syntax-help-variable -as-object-name) –