user4951
user4951

Reputation: 33080

What is wrong with this Macro?

#define mySynthesize(op) @synthesize op = _op;

So rather than typing

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

I can just do

mySynthesize (someVar);

Well, it doesn't work though. What did I do wrong?

Upvotes: 2

Views: 124

Answers (1)

ughoavgfhw
ughoavgfhw

Reputation: 39905

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

Upvotes: 10

Related Questions