Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate constants Objective-C ios [duplicate]

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.

like image 957
rafamvc Avatar asked Aug 09 '12 18:08

rafamvc


2 Answers

you can do this with macro use:

#define WEBSITE_URL @"http://192.168.1.15:3000/"
#define API_URL WEBSITE_URL @"api/"
like image 170
Saurabh Passolia Avatar answered Sep 24 '22 08:09

Saurabh Passolia


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/";
like image 24
Graham Perks Avatar answered Sep 22 '22 08:09

Graham Perks