Objective c 目标C:访问#按stringWithFormat定义

Objective c 目标C:访问#按stringWithFormat定义,objective-c,Objective C,有没有办法访问#通过stringWithFormat定义的,e。G在一个循环中 例如: #define text1 @"AAA" #define text2 @"BBB" #define text3 @"CCC" ... 循环: for (int i = 1; i < 10; i++) { NSLog(@"%@",[NSString stringWithFormat:@"text%i",i]); //want to access #defines here } for(int

有没有办法访问#通过stringWithFormat定义的,e。G在一个循环中

例如:

#define text1 @"AAA"
#define text2 @"BBB"
#define text3 @"CCC"
...
循环:

for (int i = 1; i < 10; i++) { 
    NSLog(@"%@",[NSString stringWithFormat:@"text%i",i]); //want to access #defines here
}
for(inti=1;i<10;i++){
NSLog(@“%@,[NSString stringWithFormat:@“文本%i”,i]);//要访问这里的定义吗
}
#define
只能访问
NSLog(@“%@”,text1)

您的
[NSString stringWithFormat:@“text%i”,i]
将生成text1字符串not variable。 , 要完成所需任务,您最好使用数组:

NSArray *array = @[@"AAA", @"BBB", @"CCC"];
NSLog(@"%@", [array objectAtIndex:i]);

否。
#define
仅在编译时使用,而不是在运行时使用。是否必须这样定义字符串?也许你可以将它们存储在数组中?你以前使用过哪些语言?如果你用C/C++编程,你应该明白你不能这么做。如果只有Java,那么也许您可以原谅。使用
stringWithFormat
是不可能的,但使用其他在compiletime中迭代定义的宏也是可能的。抱歉,太复杂了,现在无法提供代码。