在PHP和JavaScript中,您可以通过使用另一个变量作为其名称的一部分来动态使用变量.我不想将数组用作解决方案的一部分.这可以在Objective C中实现吗?我想做这样的事情:
for (int i=1; i<6; i++) {
if([appRecord.answer(i) length] != 0){
self.textView.answer(i)ViewSingle.text = appRecord.answer(i);
}
}
Run Code Online (Sandbox Code Playgroud) 如何NSDictionary使用数组计数创建多个变量?
这基本上就是我提出的,但我不确定如何使用Objective-C语法来完成这项工作.doesntContainAnother是一个NSArray.我希望字典的名称使用当前值loopInt.
int *loopInt = 0;
while (doesntContainAnother.count <= loopInt) {
NSMutableDictionary *[NSString stringWithFormat:@"loopDictionary%i", loopInt] = [[[NSMutableDictionary alloc] init] autorelease];
[NSString stringWithFormat:@"loopDictionary%i", loopInt] = [NSDictionary dictionaryWithObject:[array1 objectAtIndex:loopInt]
forKey:[array2 objectAtIndex:loopInt]];
loopInt = loopInt + 1;
}
Run Code Online (Sandbox Code Playgroud)