Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Objective-C string using stringification

Tags:

objective-c

I'm trying to create an Objective-C string using the '#' and '##' operators. I've written the following macros:

#define OBJCKEY(p, s) p ## s
#define KEY(k) OBJCKEY(@, #k)

Which I'm trying to use in a function in the following way:

NSString *key = KEY(EnumValue1);

But Xcode reports the following error:

Pasting formed '@"EnumValue1"', an invalid preprocessing token

Any idea on how to fix this?

Note: I'm using the LLVM compiler.

like image 817
g_fred Avatar asked May 13 '26 03:05

g_fred


1 Answers

Any idea on how to fix this?

Is there anything wrong with

NSString* key = @"EnumValue1";

Or how about

#define KEY(k) (@#k)

NSString* key = KEY(EnumValue1);
like image 146
JeremyP Avatar answered May 14 '26 17:05

JeremyP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!