Xcode project's "Build number"
Additionally, if you add CFBuildDate as a string and CFBuildNumber as a string into your info.plist, the following shell script (when added to your run script build phase /bin/bash will automatically update your build number and date:
# Auto Increment Version Script
buildPlist=${INFOPLIST_FILE}
CFBuildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
CFBuildNumber=$(($CFBuildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $CFBuildNumber" $buildPlist
CFBuildDate=$(date +%Y%m%d%H%M%S)
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" $buildPlist
I'm using Xcode 4.3.3 (4E3002) and managed to have build number (CFBundleVersion) automatically increased every build with the following steps:
- Select the menu item Product/Edit Scheme... (Command+<)
- Expanded the Build phase
- Select Pre-actions
- Clicked on the plus sign to add "New Run Script Action"
- Entered "/bin/bash" as the "Shell"
- Select one of the targets in "Provide build settings from"
Entered the following code:
buildPlist=$SRCROOT/$INFOPLIST_FILE PlistBuddy="/usr/libexec/PlistBuddy" CFBundleVersion=`$PlistBuddy -c "Print CFBundleVersion" $buildPlist` CFBundleVersion=$(($CFBundleVersion + 1)) $PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" $buildPlist
Have fun!
Many people use the build number to track the total number of times a project is "built" (simply compiled for small projects, maybe some more involved process for larger ones).
The build number is an absolute value incremented every build. A version number, on the other hand, is an arbitrary "label" or "tag" used as shorthand for a specific build number.
So say you've built your project 123 times, your build number is "123", but you might decide to refer to that as "version 1.0" for simplicity sake. If you build another 20 times to fix a bug, your build number is 143, but your version is "1.01" or "1.1" or whatever you decide to name it.
I've also seen projects that base their build numbers on source control. So a CVS/SVN team might use the revision number as their build number. I've also seen git projects that use the SHA of the latest commit as a build number (although some management tools assume the build number is an incremental value — and obviously in the case of SHAs, it's not).