Feb 19, 2020:  ~ 2 min read

Sync build versions between targets

I've been working for a while on a new project (stay tuned!) which has a watch app. Up until now I used a script that automatically increases the build number of the app, based on the value in Info.plist:

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

This works really well, but the problem with watch targets is that the build number has to be the same for all targets. First idea was to just add this build script to all targets, which might work well, but it just felt wrong.

Xcode offers a build setting called CURRENT_PROJECT_VERSION, which exists at the project level. If you go in each target and delete this setting (if it exists), it means each target will inherit the value found at the project level.

Step 1 accomplished: a single source of truth.

Step 2: automating it. I replaced the PlistBuddy script above with the much simpler one below, added as a build phase on the main app's target:

xcrun agvtool new-version $NEW_VERSION ❷

What this does is it first reads the current version and adds 1 to it (❶), it then passes it to xcrun's agvtool to be set as the new version (❷).

I think it's much simpler and more elegant this way, even for a single target.

Subscribe to my monthly newsletter.
No spam, unsubscribe at any time.