In Xcode 4 look in the Navigator pane, which is the pane on the left side of the Xcode screen. It has 7 icons across the top. Select the left-most icon (looks like a file folder) to get the Project Navigator pane.
Now click on the first item in that pane, which is the project itself. That opens a big window in the center with a narrow column to the left of it.
The narrow column has 2 sections: “PROJECT” AND “TARGETS”. Click on your project name in the “TARGETS” section. Now the center pane has 5 tabs along the top: “Summary”, “Info”, “Build Settings”, “Build Phases”, and “Build Rules”.
Click on the “Build Phases” tab. If your config is the same as mine you’ll now see 4 sections in the main window: “Target Dependencies”, “Copy Bundle Resources”, “Compile Sources”, and “Link…”. Click on “Add Build Phase” (at the lower right corner) and choose “Add Run Script”. A 5th section now appears in the center pane with the title “Run Script”. Drag the “Run Script” section up so it is the 2nd section from the top, just below “Target Dependencies”.
Now click on the disclosure triangle for the Run Script section. That opens a window where you can put a script. Copy and paste the following script into that window.
#!/bin/bash bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE") bN=$((0x$bN)) bN=$(($bN + 1)) bN=$(printf "%d" $bN) /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "$INFOPLIST_FILE"
Be sure that “Run script only when installing” is NOT CHECKED.
That’s it! Now your build number auto-increments every time you build your project.
This script assumes you have a decimal build number in your Info.plist file and increments it as hex. The build number appears in Info.plist as “Bundle version”. The script doesn’t work if the build number is missing so be sure to enter a starting value. To enter a starting value go to the “Summary” tab in the same center pane you were using above and enter “1” (or whatever value you like) into the “Build” box (but not a formatted string like 1.0).