How to synchronize versions and build numbers across different targets
Tags: ios, xcode, swift, objectivec
Published: 2020-09-27 18:22:34

---
title: How to synchronize versions and build numbers across different targets
published: true
date: 2020-09-27 18:21:32 UTC
tags: iOS, xcode,swift,objectivec
canonical_url: https://www.rockandnull.com/how-to-synchronize-versions-and-build-numbers-across-different-targets/
---

 ![How to synchronize versions and build numbers across different targets](https://images.unsplash.com/photo-1601205866516-f42ce3289f98?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=2000&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ)

If you ever developed an extension for iOS, you are most likely to be familiar with the following errors when uploading the app in the App Store:

**CFBundleVersion Mismatch** - The CFBundleVersion value '1' of extension 'ExtensionApp' does not match the CFBundleVersion value '2' of its containing iOS application 'Main.app'.

**CFBundleShortVersionString Mismatch** - The CFBundleShortVersionString value '1' of extension 'ExtensionApp' does not match the CFBundleShortVersionString value '2' of its containing iOS application 'Main.app'.

If you have only one extension it's not that difficult to keep them synchronized, but things get tricky when you add more than one extension. In my case, I have a project that has 6 targets and I need to keep the synchronized.

Since we are programmers, and our job is to solve problems, I thought that it must be a better way to synchronize the target's versions! The first thing that came to my mind was to use `Run Script Phase` but then I thought it will get messy for 6 different targets.

<iframe width="100%" height="386" scrolling="no" border="no" allowtransparency="true" frameborder="0" style="border:none!important;width:100%!important;height:386px;position:relative;" src="https://upscri.be/ltv52r?as_embed=true"></iframe>

After digging around, I found a much better and much cleaner solution. We will use the **User-Defined** setting that they will be used by all of the targets.  All we have to do is go to the project's `Build Settings`, click on the plus sign and add two settings and call them `APP_VERSION` and `APP_BUILD`.

![How to synchronize versions and build numbers across different targets](https://www.rockandnull.com/content/images/2020/09/Screenshot-2020-09-27-at-6.45.07-PM-1.png)<figcaption>Adding the User-Defined Settings</figcaption>

You will find the newly added settings at the bottom of the `Build Settings` tab. Set the `APP_VERSION` to match the main target's version (eg. `3.4.1`)  and the `APP_BUILD` to match its build number (eg.`15`).

These settings are accessible throughout the project using the `$(APP_VERSION)` and `$(APP_BUILD)` variables. Now, we need to go through each target's `Info.plist` file and set the `Build Version` value to `$(APP_BUILD)` and the `Build Version String (short)` to `$(APP_VERSION)`. From now on, you should be changing the version and the build number from the `Build Settings`.

![How to synchronize versions and build numbers across different targets](https://www.rockandnull.com/content/images/2020/09/Screenshot-2020-09-27-at-6.51.10-PM.png)

That's it!

Happy coding!

[Say hello](mailto:hello@rockandnull.com) or [tweet us](https://twitter.com/rockandnull)!