When you create an iOS Application in XCode by default the version of the application is stored in-Info.plist. It would be really handy to get this in to code for compile time checks and #defines.
PList files are actually XML files which makes them easy to read in a shell script but complex to manipulate in bash. Luckily there is a utility called PListBuddy installed in /usr/libexec (not the usual path for command line utilities in OS X) which can manipulate PList files in various ways. For example:
showing that the current development version of stranded is 0.28 (long way to go to get to 1.0)
I wanted to output a header file called version.h from my various targets based upon the value of CFBundleVersion in Stranded-Info.plist. To accomplish this I added a small build step to each target which ran the following script:
1 2 3 4 5 6 7 8 9 10 11
This should be placed as a ‘New Run Script Build Phase’ with your info.plist file as input and your output file as the version.h file you want to generate.
It’s important that this build script is the first script to run so that version.h is updated BEFORE the application code is built.
I’ve renamed the build script to “Update Version” so I remember what it is.
Now in code you can write:
1 2 3