How to define strings in xcconfig and quotes

I started using the xcconfig file for specific build settings and I noticed that the string quotes are being interpreted literally.

eg.

APP_BUNDLE_DISPLAYNAME_SUFFIX = "DEBUG"

will display the app name MyApp "DEBUG"

as the display name (with quotes)

How do you handle the lines in the xcconfig file, are they needed to define the lines? If not, how do you deal with the empty space and run away? Any special characters known about?

+3


source to share


1 answer


The answer is that it depends on the actual setup of the assembly you are trying to change and where it is being used.

As you noticed, a type setting APP_BUNDLE_DISPLAYNAME_SUFFIX

can only take one word, and therefore adding quotes here causes them to be included in the parameter value by Xcode.

However, in other places it is different. In particular, if the assembly has a toolchain setup built in. In these cases, you need to use quotes and escaping for Xcode command line AND .

For example: if you want to use the xcconfig file to set preprocessor definitions (i.e. macros) and you want to define a string macro, you need to escape the quotes so that the shell doesn't remove them, and if you have forward slashes in the string then you also need to you will have to avoid them because Xcode interprets them internally.

Let's assume you have in your code:



#ifdef MY_MACRO1
const char *my_url = MY_MACRO2;
#endif

      

Then this xcconfig file will work correctly:

//
//  my_string_macro.xcconfig
//

GCC_PREPROCESSOR_DEFINITIONS=MY_MACRO1 MY_MACRO2="\"https:\/\/stackoverflow.com\/questions\/30926076\/\"" 

      

The Xcode Build Settings inspector will show the value between the outer two double quotes unchanged, but it will be interpreted correctly at compile time, resulting in something like this in the compilation log:

clang -x objective-c++ -DMY_MACRO1 -DMY_MACRO2=\"https://stackoverflow.com/questions/30926076/\"

      

+1


source







All Articles