I would like to concatenate a string and a double (or in this case concatenate a #defined constant).
I want to insert the CURRENT_LATITUDE and CURRENT_LONGITUDE values into the NSURL that I’m creating with URLWithString:
#define CURRENT_LATITUDE 37.000000
#define CURRENT_LONGITUDE -120.000000
NSURL *jsonURL = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/json?location=" + CURRENT_LATITUDE + "," + CURRENT_LONGITUDE + "@f&radius=100&sensor=true&types=establishment&key=blahAPIkey123"];
I know the + signs don’t work, so please help me understand how to do this. In Lua you can use
.. CURRENT_LATITUDE ..
So what should I use in Objective-C?
Use NSString’s
stringWithFormatmethod, which works exactly like printf, it looks for format specifiers in the first argument, and then one extra argument per specifier.