Autobuild numbers in Xcode4

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).

Advertisements
Tagged with: , , ,
Posted in Uncategorized
One comment on “Autobuild numbers in Xcode4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
%d bloggers like this: