How to combine two NSString? How to combine two NSString? xcode xcode

How to combine two NSString?


To get what you want you can use

NSString *coordinates = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];


Just use stringWithFormat method

[NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];


A thousand years late:

[latitudeString stringByAppendingFormat:@",%@", longitudeString]

Would slightly reduce runtime parsing costs and, historically, would have given you greater type safety (before the compiler checked type strings). So some of us old timers got used to it and still mentally make the fairly feeble performance argument to justify what's comfortable.

[@[latitudeString, longitudeString] componentsJoinedByString:@","]

May also be preferable if you'd rather raise an exception upon one string being missing than silently produce something nonsensical.