Skip to content

Instantly share code, notes, and snippets.

@neverunlucky
Last active August 22, 2018 11:12
Show Gist options
  • Save neverunlucky/7d3b0430daa32cf9bcc54d65c1003435 to your computer and use it in GitHub Desktop.
Save neverunlucky/7d3b0430daa32cf9bcc54d65c1003435 to your computer and use it in GitHub Desktop.
Objective-C marco define symbol to NSString
//Credit: https://stackoverflow.com/questions/1793882/how-to-make-a-macro-that-can-take-a-string
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
#define PASTE2(a, b) a##b
#define PASTE(a, b) PASTE2(a, b)
#define PRINTTHIS(text) \
NSLog(PASTE(@, STRINGIFY(text)));
//Result
#define PRINTTHIS(abcde) \
NSLog(@"abcde");
//Result
#define abcde ongggg
NSLog(@STRINGIFY(abcde));
//output: ongggg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment