我想要一个可以这样使用的宏:
CREATE_URL(@"{SOME-TOKEN}/some/url/path");
然后,宏应将我的 token 类似物替换为以下调用:
NSString *initialURL = @"{SOME-TOKEN}/some/url/path";
[initialURL stringByReplacingOccurencesOfString:@"{SOME-TOKEN}" withString:@"http://server.com"]
因此,我已经定义了这样的宏,不幸的是它无法正常工作:
#define CREATE_URL(url) [##url stringByReplacingOccurencesOfString:@"{SOME-TOKEN}" withString:@"http://server.com"];
我在使用宏时遇到两个错误:
Missing '[' at start of message send expression
Pasting formed '[@', an invalid preprocessing token
最佳答案
为什么不呢?
#define CREATE_URL(url) [url stringByReplacingOccurencesOfString:@"{SOME-TOKEN}" withString:@"http://server.com"]
它应该可以正常工作...为什么##和;?
关于ios - 宏用于重复出现的字符串替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435459/