Automatic Build Number Increment in Xcode

Another cheat sheet so I can quickly find it later, just in case. As is well known, in Xcode you can run your own bash scripts while building a project.

These 2 lines of code allow you to automatically increment the build number in the app:

buildNumber=$(git rev-list --all | wc -l)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

The first line counts the number of commits in the git repository. The second writes that number to the target's .plist file as the build number. Each new commit increments the build number by one. This is one way to do it.

Put it into the required target's Build Phases.