A while back I had posted on concatenating NSString objects. Now that we have literal notation, let’s see how much easier and terse we can make this, hmmmm?
Here is the category on NSArray:
@interface NSArray (StringUtilities) - (NSString *)string; @end @implementation NSArray (StringUtilities) - (NSString *)string; { return [self componentsJoinedByString:@""]; } @end
Before, using my category on NSString would make concatenation work like this:
NSString *test = [NSString concatenate:@"This", @" is", @" a", @" test.", nil];
Now, the same thing with the category on NSArray looks like this:
NSString *test = @[ @"This", @" is", @" a", @" test." ].string;
Not as wordy and easier to type. I think I like it! Here’s a gist!