Subscribe to
Posts
Comments
NSLog(); Header Image

Obj-C String Concat

Chris is looking for a better way to concatenate strings in Objective-C than the fairly cumbersome stringByAppendingString:. PHP uses the . (dot) operator.

Of course, there's also [NSString stringWithFormat:@"%@", someObj];. We've used that a few times in some of our apps.

3 Responses to "Obj-C String Concat"

  1. I don't have any experience with Objective C, but does it have operator overloading?

    Might be an easy way to get it how you want it - the '.' in PHP and Perl are basically overloads themselves, same with '+' in Java.

  2. Objective-C doesn't have operator overloading.

    The solution here might be to add a category or something.

  3. There's no way in C (and thus Objective C) to define infix macros or functions, so you're SOL here.

    If you're concatenating a lot of stuff, you should use a mutable string anyways.