how to pass the user-defined macro to xcodebuild?

Viewed 8019

I build my project by xcodebuild in command line. Not in xCode. I want to pass some marc to the project so that it can affect the code. Such as code below:

#if (API_TYPE == 1)
  #define URL_API @"https://dapi.xxx.com/1.1/"
#elif (API_TYPE == 2)
  #define URL_API @"https://tapi.xxx.com/1.1/"
#elif (API_TYPE == 3)
  #define URL_API @"https://api.xxx.com/1.1/"
#else
  #error "API_TYPE value error! should be only value 1,2,3 !"
#endif 

I want pass the define of API_TYPE outside the code files. Such as through xcodebuild command. But It doesn't work like this:

xcodebuild -sdk xxx -target xxx SYMROOT=${XCSYMROOT} API_TYPE=${APITYPE}

The API_TYPE's value was not changed. But the SYMROOT's value was changed. So how can I implement that passing the value to API_TYPE outside ?

2 Answers
Related