I defined a macro MYMACRO. Note: the value is not a valid NSString.
#define MYMACRO is
The macro is used inside the declaration of a NSString
@"This MYMACRO fun"
However, the preprocessor does not expand the macro. The preprocessed result is
@"This MYMACRO fun"
The best solution I found so far to get the macro to expand is:
#define MYMACRO @"is"
@"This "MYMACRO@" fun"
The macro expands as below which is a valid Objective-C syntax:
@"This "@"is"@" fun"
However, this requires 2 concatenation at runtime.
So my question is how to insert a macro insto a NSString without using any string concatenation at runtime ?
Ideally, I would like the runtime execute @"This is fun"
rather than @"This "@"is"@" fun"
I'm fairly certain what you have is already concatenating at compile time, and not runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With