typeoneerror typeoneerror - 5 months ago 17
Objective-C Question

Shortcuts in Objective-C to concatenate NSStrings

Are there any shortcuts to (

) string concatenation in Objective-C, or shortcuts for working with
in general?

For example, I'd like to make

NSString *myString = @"This";
NSString *test = [myString stringByAppendingString:@" is just a test"];

something more like

string myString = "This";
string test = myString + " is just a test";


Two answers I can think of... neither is particularly as pleasant as just having a concatenation operator.

First, use an NSMutableString, which has an appendString method, removing some of the need for extra temp strings.

Second, use an NSArray to concatenate via the componentsJoinedByString method.