Skip to content

Auto-Increment Build Numbers in Xcode

Oohhh I forgot to update my build number!
You’re working on some cool app and client expects from you have to make a friday-build so he could test it. You select Product – Archive. Upon successful archiving, you want to upload build to Test Flight and you see some bad message which says that you’re already uploaded build with the same number. Ah…

So what should we do then?
Select Project, go to Build Phases and above the Target Dependencies you’ll see a small “+” button. You tap on it and select New Run Script Phase.

At the bottom, a new Section will be created ‘Run Script’ and you will see like a small Terminal-like window where you can paste your code.

So you paste this:

1
2
3
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")  
buildNumber=$(($buildNumber + 1))  
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

I hope this small tip can be very useful for your future projects

Have a fun day! Happy coding!

Published inTips & Tricks

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: