Question

Is it possible to read a value from my Info.plist file in the prefix.pch file and sat a macro according to that value?

For instance, if I have a boolean property in the Info.plist called UseSomeResource I would like to make a #define USE_SOME_RESOURCE 1 if the value of that property is YES.

Was it helpful?

Solution

In theory yes, albeit I don't think the .pch is the best place to put it. I'd suggest placing this macro within a Macros.h, or some similar mechanism, that you import within your .pch

#define USE_SOME_RESOURCE ([[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UseSomeResource"] boolValue])

More about .pch can be read here

It's worth noting that this will still determine the value at runtime, not at compile time. If you want it to be run at compile time, you may need to write a script as part of one of your build phases, that reads the Info.plist, and creates a header file, which is then included as part of your project. This seems like quite a roundabout method, and as such I highly suggest the runtime alternative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top