Alex Rivera | Logout

Concatenate constants Objective-C ios

Asked 2012-08-09T18:50:16.263
9

Possible Duplicate:
How to create constant NSString by concatenating strings in Obj-C?

I have two constants that I would like to concatenate:

NSString * const WEBSITE_URL = @"http://192.168.1.15:3000/";
NSString * const API_URL = @"http://192.168.1.15:3000/api/";

Normally in other languages I would concatenate the WEBSITE_URL in API_URL, but you can't concatenate a compile time constant since stringWithFormat or anything like it is a runtime, not compile time method.

Edit
Report

1 Answer

9

You could drop to the preprocessor.

#define WEBSITE_URL_DEF "http://192.168.1.15:3000/"

NSString * const WEBSITE_URL = @WEBSITE_URL_DEF;
NSString * const API_URL     = @WEBSITE_URL_DEF "api/";
answered 2012-08-09T18:58:25.337

Your Answer