Last active
March 18, 2021 12:50
-
-
Save willeccles/20beead52d2717f2b17efccf06ebc6e3 to your computer and use it in GitHub Desktop.
How to easily concatenate strings in Objective C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! :)