37

I was wondering if Xcode 5 is providing a setting to automatically count up the Build number found under General in the Identity section of the project navigator.

But afaik you still have to do it with scripting, using PlistBuddy.

One simple solution is to increase the build number in Xcode 5 is posted below:

seinfeld
  • 1,686
  • 1
  • 17
  • 18

1 Answers1

92

Go to Editor -> Add Build Phase -> Add Run Script Build Phase

Add Run Script Build Phase

Go to Build Phases in the project navigator and edit Run Sript. Change Shell to /bin/bash and paste the following script:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

Enter PlistBuddy Script

Don't forget to change the Build number found under General in the Identity section from 1.0 to 1

Have fun! :)

I found this tutorial on Cocoa Factory

seinfeld
  • 1,686
  • 1
  • 17
  • 18
  • 4
    Poor solution as the build number will increment every time a build is performed, whether a source file has changed or not. That's not very useful and this solution is better: http://stackoverflow.com/questions/9258344/xcode-better-way-of-incrementing-build-number – trojanfoe Jan 14 '14 at 13:25
  • 2
    I changed the "$INFOPLIST_FILE" string to "${PROJECT_DIR}/${INFOPLIST_FILE}". Then I edited the scheme and put the script in as a "post-action". I made sure to check the "Provide build settings from " and set the shell to /bin/bash. I put it as a post-action so that I know exactly what build I'm doing. Great for simple apps. I recommend a makefile for automated builds for more serious applications. Happy coding! – ryanconnellyatl Mar 18 '14 at 02:46
  • Note that this will fail if your current CFBundleVersion includes a decimal, e.g. "1.0". Shell scripts can only add integers with the raw + operator. – Stan James Mar 25 '14 at 17:12
  • Is there a way to automatically add this to ever project? – mginn Jul 11 '14 at 16:24
  • 4
    @trojanfoe this worked fine for me as long as you check the 'run script only when installing checkbox' – Imran Oct 06 '14 at 11:09
  • 3
    For anyone wondering "[Run script only when installing](http://stackoverflow.com/questions/5913199/xcode-run-script-build-phase-run-script-only-when-installing-option)" will only run the script when you Archive your app for upload. – nacross Nov 03 '14 at 11:20
  • I'm trying to get this working in Xcode 6.1 with a Swift project but the Add Run Script Build Phase menu item is disabled. Does anyone know why? – BadmintonCat Nov 17 '14 at 10:59
  • Nevermind! Could add it via the Build Phases Tab! – BadmintonCat Nov 17 '14 at 11:02
  • 9
    To add the script in Xcode 6.1 you need to go to Your Project > Build Phases Tab and then click the little '+' towards the top left, right below the bar with all the tabs on it. Click "New Run Script Phase" – Nick Yap Dec 22 '14 at 03:17