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
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:
NEW_VERSION=$(($CURRENT_PROJECT_VERSION + 1)) ❶ 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
agvtool to be set as the new version (❷).
I think it's much simpler and more elegant this way, even for a single target.