通过同名字符串名称检索NSString的值

时间:2019-04-24 19:46:29

标签: objective-c nsstring

我想通过循环将一系列带有增量后缀的NSString加入。一旦在循环内部生成了正确的字符串名称,如何检索在循环外部定义的同义字符串的相应值?

NSString *Element_1 = @"Andrew";
NSString *Element_2 = @"John";
NSString *Element_3 = @"Jane";
NSString *Element_4 = @"Sarah";

NSString *finalStr;
NSString *elemName;
NSString *elem;
for (int i=1; i<5; i++)
{
    elemName = [NSString stringWithFormat:@"Element_%i", i];
    elem = //?? value of string with name defined before the loop
    finalStr = [finalStr stringByAppendingString:elem]; 
}

0 个答案:

没有答案