开发者

What is wrong with this Macro?

开发者 https://www.devze.com 2023-04-06 02:01 出处:网络
#define mySynthesize(op) @synthesize op = _op; So rather than typing @synthesize someVar=_someVar; @synthesize otherVar=_otherVar;
#define mySynthesize(op) @synthesize op = _op;

So rather than typing

@synthesize someVar=_someVar;
@synthesize otherVar=_otherVar;

I can just do

mySynthesize (someVar);

Well开发者_Python百科, it doesn't work though. What did I do wrong?


When you prefix the op with an underscore, the preprocessor treats it as a different token, so it doesn't get replaced. You need to use ## to concatenate the underscore to the front so that the replacement occurs first.

#define mySynthesize(op) @synthesize op = _ ## op
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号