Automatically Insert Your SVN Revision Number Into Your Xcode Project

Oct 21, 2009   //   by Derek van Vliet   //   Development  //  No Comments

Wouldn’t it be handy for your iPhone app to have access to its subversion revision number at run-time? Of course it would!

Being able to access the current revision number in your app is especially useful for testing. We use it to display the current rev on our test builds so our testers can reference the build that they discover bugs in, like so:

IMG_01632

Here’s how to do it

1. In Xcode, add an empty header file to your project’s “Other Sources” group called “revision.h”.

2. Add a “New Run Script Build Phase” to your target.

3. When defining your build phase, use “/bin/sh” for the Shell value and enter the following script:

REV=`svnversion -n`
echo "#define kRevision @\"$REV\"" > ${PROJECT_DIR}/revision.h

4. Ensure that the new build phase happens before your “Compile Sources” build phase.

5. Build your app.

That’s it! From now on you can use a string define called kRevision wherever you would like to reference your revision number at run-time.

IMPORTANT: Do NOT add your revision.h file to your subversion repository. It will be generated automatically each time you build your app.

Leave a comment

Our Games

Latest Tweets