2012-05-03 37 views
1

我想要一個宏,我可以用這樣的:宏重新發生的歷史字符串替換

CREATE_URL(@"{SOME-TOKEN}/some/url/path"); 

宏則應該更換我的令牌模擬下列電話:

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 

回答

4

爲什麼不是這個?

#define CREATE_URL(url) [url stringByReplacingOccurencesOfString:@"{SOME-TOKEN}" withString:@"http://server.com"] 

應該做工精細......爲什麼##和;?

+0

我認爲你是對的,那麼##符號是什麼? – Besi

+0

它用於擴展宏。例如,如果您需要在編譯時使用Macro http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage生成的變量名%2Fref%2Fnumnum.htm –