Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active March 18, 2021 12:50
Show Gist options
  • Save willeccles/20beead52d2717f2b17efccf06ebc6e3 to your computer and use it in GitHub Desktop.
Save willeccles/20beead52d2717f2b17efccf06ebc6e3 to your computer and use it in GitHub Desktop.
How to easily concatenate strings in Objective C
// This is a genius macro from EthanB on StackOverflow
// It's meant to work around Obj-C's missing string concatenation operator
// answer: http://stackoverflow.com/a/16862414/2712525
#define stringConcat(...) \
[@[__VA_ARGS__] componentsJoinedByString:@""]
// so now instead of this...
NSString *str = @"things are ";
NSString *str2 = [str stringByAppendingString:@"cool."];
//...you can do this:
NSString *str = @"things are ";
NSString *str2 = @"really ";
NSString *final = stringConcat(str, str2, @"cool!");
@RaffaeleNachos
Copy link

Thank you! :)

@willeccles
Copy link
Author

@RaffaeleNachos Wow, I forgot I even wrote this. Glad it could help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment