Search code examples
iosobjective-cc-preprocessorinfo-plist

InfoPlist.strings vs a global.h for constants


If I want to declare a constant string (not necessarily changing based on language) that can be used in multiple .m files should I do that in my InfoPlist.strings or should I create a separate global.h file and use #define?

The research I've done makes me thing global.h is the way to go but I want to make sure.


Solution

  • It depends on what type of constant you need. For a simple string constant, using a .strings file has an advantage in that it doesn't need to re-compile the binary to have the values available inside the app, on the other hand, makes it easier for a hacker to modify.

    Using a .h to store constants is better if you want to store numerics, as parsing an integer from a string is no small task.

    Most of the time, I would say that a .h is better, but beware of pitfalls of using one! You cannot take an address of a constant in a .h (which normally you don't have to use), and comparing a string with == and a constant is a no-no.