HeisenBerg HeisenBerg - 2 months ago 17
iOS Question

Objective C Macro append to string

I think this is a very simple thing to do, but since I'm new to iOS development and objective C, I can't figure it out.

#define RESTFUL_PATH_PREFIX @"https://gogch.com/gch-restful";
#define LOGIN RESTFUL_PATH_PREFIX @"/login;


I want the result
"https://gogch.com/gch-restful/login"


but I'm getting the result as
"https://gogch.com/gch-restful"


other topics in stackoverflow mention only about adding a new string to the beginning of a string like,

#define DOMAIN "example.com"
#define SUBDOMAIN "test." DOMAIN

Answer

Remove the trailing semi-colon:

#define RESTFUL_PATH_PREFIX @"https://gogch.com/gch-restful";
                                                            ^

and then string constants can be concatenated by the compiler:

@"first" @"second"

instead of:

@"first"; @"second"
Comments