Auto Increment Your Build Numbers
If you're like me you probably get tired of manually incrementing your app build number in Xcode. After a few hours of testing I finally nailed down a simple solution that works on Xcode 13.2.1. Let's dive right in.
Note: I like to increment the build number after a successful Archive, but you may want to do it after each Run. I recommend that you don’t increment the build number in the Test or Build pre or post actions as this will result in strange issues while running tests, among other things (believe me, I tried this and it wasn’t pretty).
Here are the steps to auto increment the build number after successful archives:
- Open your scheme settings (Product > Scheme > Edit Scheme [or] click your scheme in the top bar and then click Edit Scheme [or] shift + command + ",")
- Expand the Archive settings
- Click Post-actions
- Click the "+"
- Click New Run Script Action
- Make sure "Provide build settings from ..." is set to your target (the script needs access to the project directory variable)
- Paste in this code
It should look something like this:
You're all set! Run an archive build & watch the build number increment across your entire project once the archive completes.
Notes:
- You might not have noticed the quotes around ${PROJECT_DIR} - I've seen some solutions that didn't include those & it prevents the process from switching to the correct directory.
- agvtool is a helper tool that comes with Xcode command line tools. If you don't have the command line tools installed, just open terminal and type xcode-select --install then follow the prompts.