如何在#define中使用两个字符串?

时间:2011-06-17 10:29:31

标签: objective-c c-preprocessor

我正在使用

#define SITO @"http://localhost:3000"
#define MISSING @"http://localhost:3000/photos/large/missing.png"

是否可以动态执行此操作?我的意思是

#define SITO @"http://localhost:3000"
#define MISSING @"<<SITO>>/photos/large/missing.png"

2 个答案:

答案 0 :(得分:4)

使用...

#define MISSING SITO @"/photos/large/missing.png"

答案 1 :(得分:0)

你不允许你在其他人中嵌入一个微观。但你可以按照@Simon Lee的建议进行嵌套。

使用以下方法。

#define SITO @"http://localhost:3000"
#define MISSING @"<<%@>>/photos/large/missing.png"

将字符串构造为belwo。

NSString* Missing = [NSString stringWithFormat:MISSING,SITO];
NSLog(@"Missing %@", Missing);