<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anmol Suneja on Medium]]></title>
        <description><![CDATA[Stories by Anmol Suneja on Medium]]></description>
        <link>https://medium.com/@anmol-suneja?source=rss-55d6b43d88ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OiqNt41l8PEeLFo4tHDxFA.png</url>
            <title>Stories by Anmol Suneja on Medium</title>
            <link>https://medium.com/@anmol-suneja?source=rss-55d6b43d88ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:02:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anmol-suneja/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Distributing configurable iOS app for multiple servers using configurations, schemes and settings…]]></title>
            <link>https://medium.com/geekculture/distributing-configurable-ios-app-for-multiple-servers-using-configurations-schemes-and-settings-2e48460df18?source=rss-55d6b43d88ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e48460df18</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Anmol Suneja]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 18:33:53 GMT</pubDate>
            <atom:updated>2023-09-03T04:30:32.613Z</atom:updated>
            <content:encoded><![CDATA[<h3>Distributing configurable iOS app for multiple servers using configurations, schemes and settings bundle</h3><p>Almost every app points to a server to fetch some information and processes this information to show that in user friendly way. Each app needs to pass a set of validations before it makes its way to app store. For testing, QA team is there and they may request for builds pointing to different servers (like staging, production/release).</p><h3><strong>What if QA needs to test on different servers?</strong></h3><p>Developers may have kept one variable in Swift code base which points to one of server. When there is need to give builds pointing to different servers, they update that variable and rebuild the whole application again for just one change of variable and distribute those multiple builds pointing to specific servers.</p><h3><strong>Is there any way to avoid creating multiple builds?</strong></h3><p>What if we allow our QA team member to point any server they want in a single build? Yes, there is a work around. We can do that using settings bundle. There we will be showing different servers list and QA can select the desired server. On selection, we would point our app to that server.</p><p><strong>But, we don’t want this settings bundle to be shipped to end-users/customers. Right?</strong></p><p>Yes, we need to remove this settings bundle when we are shipping app to app store. That would be taken care of.</p><h3>Preparing project</h3><p>For now, let’s try to create a sample project and see how we achieve this as we proceed. Create a new demo project say DemoApp.</p><p>We need to add some configurations in project. For each server, we would be adding one configuration file. Also, apart from configurations specific to each server, we need one more configuration file specific to build that give user capability to point to any server.</p><p><strong>How to add configuration settings file?</strong></p><p>Select File → New → File. Choose iOS template <strong>Configuration Settings File.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2YZg0E-UnwnAoTH3zsHiw.png" /><figcaption>Xcode Config</figcaption></figure><p>Press Next and name the config file say <strong>Staging. </strong>(Specific to staging server). Similarly, create more config file, say <strong>Development</strong>, <strong>Release, Configurable</strong>. In each config file, add a variable say <strong>APP_ENVIRONMENT</strong> which have a unique value specific to each config. Please note, there is no need to add xcconfig file in target bundle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cm7v08KEMLUKg3nmkjX2WA.png" /><figcaption>ConfigurationParameter</figcaption></figure><p>As you can see, with reference to above snapshot, I had created four configurations, each having one variable <strong>APP_ENVIRONMENT </strong>which has unique value specific to each configuration.</p><pre>1. Development.xcconfig having APP_ENVIRONMENT = Development</pre><pre>2. Staging.xcconfig having APP_ENVIRONMENT = Staging</pre><pre>3. Release.xcconfig having APP_ENVIRONMENT = Release</pre><pre>4. Configurable.xcconfig having APP_ENVIRONMENT = Configurable</pre><p>Add the same variable in Info.plist file to read back in code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e72gex1fg7hQseAhw0a1cw.png" /><figcaption>UniqueParameterInfoPlist</figcaption></figure><p><strong>We have xcconfig files, now will assign them to configurations in project.</strong></p><p>Select project from left menu panel, and select the project. Under info tab, you would see two default configurations <strong>Debug</strong> and <strong>Release</strong>. Press + and add one pair of configuration dedicated to each config file. (Pair means one by duplicating debug configuration and one by duplicating release configuration).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ2idYUQq4zaea3Qxcfo3A.png" /></figure><p>Rename the configurations as desired. Let’s say we have below configurations:</p><pre>1. Debug and Release : Specific to release server</pre><pre>2. DebugDevelopment and ReleaseDevelopment : Specific to development server</pre><pre>3. DebugStaging and ReleaseStaging : Specific to staging server</pre><pre>4. DebugConfigurable and ReleaseConfigurable : Specific to configurable server. Means which user can configure using settings of app</pre><p>Did you notice <strong>No Configuration Set? </strong>in above snapshot. We need to assign xcconfig to configurations. Open configurations by clicking small arrow and set xcconfig to each specific configuration as shown in snapshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UN-ZmQg17Qdl14S1KpHJug.png" /></figure><p>Note staging xcconfig is assigned to staging configurations (<strong>DebugStaging</strong> and <strong>ReleaseStaging</strong>). Similarly, others xcconfig are assigned to their specific configurations.</p><p>Till now, we have created configurations and assigned related xcconfig having variable APP_ENVIRONMENT to related configuration. <strong>What’s next?</strong></p><h3>Creating schemes for each config..!!</h3><p>Select DemoApp scheme shown adjacent to Run/Play button and select edit scheme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DGIyY6yzpkSeyWKV7gtnOA.png" /></figure><p>See select duplicate scheme and give this duplicated scheme a name say DemoApp(Staging).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-JTGLpbGgIbXb90gbhtUA.png" /></figure><p>Similarly, create more schemes specific to each config. If you select manage schemes, you will see all the created schemes. Please ensure <strong>Shared</strong> checkmark is marked like shown in below snapshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fkknD0GXDTss4T1n5YgB5w.png" /></figure><p>Now, edit each scheme and assign proper build configuration to Debug and Archive section. Like for <strong>staging</strong> scheme, <strong>Archive</strong> build configuration should use <strong>ReleaseStaging</strong> configuration and <strong>Run</strong> build configuration should use <strong>DebugStaging</strong> configuration as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4DOEPFfT66A9Ywys7MBhw.png" /></figure><p>Everything set up, now we need to read APP_ENVIRONMENT variable in code. Let’s add one Environment file in project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e58da80c46b0b3c52856127471d01c2a/href">https://medium.com/media/e58da80c46b0b3c52856127471d01c2a/href</a></iframe><p>Update app delegate with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e4418d1fc0d200f7eb6e3725ca1bfef/href">https://medium.com/media/3e4418d1fc0d200f7eb6e3725ca1bfef/href</a></iframe><p>Now, when you run the application in debug mode using different configuration, you would be getting different values for <strong>APP_ENVIRONMENT</strong> and thereby would be able to set specific server base url in app using above code.</p><p>Try running the app, on console you should see different servers base url for different configurations. For example: for DemoApp(Staging) following is printed on console:</p><pre><strong>The app base url is: https://anmol.com/staging</strong></pre><p>Please note if you are using Pods, you need to re-install pods after setting up the project schemes and configurations.</p><h3>Adding a settings bundle for configuring the server url</h3><p>Select File → New → File. Choose iOS template <strong>Settings Bundle.</strong></p><p>Keep the name as Settings and add it to target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKu1nz854GD42SFEV060vw.png" /></figure><p>In settings, update Root.plist file. In there, we would be providing Multi Value settings with identifier say <strong>demo_app_server_preference_settings</strong>. Assign default value of server say Staging. Add titles and its corresponding values in respective order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDLgJ4x6yT36dTNjfXB8PA.png" /></figure><p>Now, when you run the app, you will see a server selection list in app settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*3leCXYg7LpxkFztpDdQL1Q.png" /></figure><p>Now, we need to set the selected server in swift code base.</p><p>Let us update the default case code block for <strong>serverBaseUrl</strong> property as mentioned below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e704baf37caad0ba8a858643e0a3a110/href">https://medium.com/media/e704baf37caad0ba8a858643e0a3a110/href</a></iframe><p>There is some duplicity of code here, we can improve this, but here its just for demo purpose, so please bear with me a little more.</p><p>Also, update app delegate so that whenever app enters foreground, we check latest pointed server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/621e08c70be3f7b371cb8741807cdf49/href">https://medium.com/media/621e08c70be3f7b371cb8741807cdf49/href</a></iframe><p>or if you are using scene delegate in code you can update it using below code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d97e76fc07af9950a9a6348a8ef0ddeb/href">https://medium.com/media/d97e76fc07af9950a9a6348a8ef0ddeb/href</a></iframe><p>Run the app again using configurable scheme and try changing the server from app settings . Verify console logs. It should be printing server base url specific to current selected server from app settings</p><h3><strong>Now, what we have?</strong></h3><p>We have different configurations (release as well as debug) which points to different servers. If developer wants to debug/archive on a particular server, they just need to select that specific scheme and app would be pointed to that server.</p><p>In case, developers want to release a build to QA then they can archive using DemoApp(Configurable) scheme and same build would be pointed to desired server selected by QA from app settings.</p><h3>What’s left?</h3><p>The settings bundle is not useful in schemes other than DemoApp(configurable) scheme. So, we will be removing that settings bundle if build configuration related to selected scheme is not configurable that is in our case for scheme DemoApp(Configurable), we need to remove settings bundle. Doing so will ensure that when we prepare a final build for end-user/customer using DemoApp scheme (dedicated to release), we are not including settings bundle in that. For this add a run-script.</p><p><strong>Add a run script by going in build phases:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6zSyHgySZIyBDDsUb6o6w.png" /></figure><p>Rename the script to anything if you want to. I renamed it to <strong>SettingBundleRemoveScript. </strong>Add following in it</p><pre>BUILD_APP_DIR=&quot;$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app&quot;</pre><pre>if [ $CONFIGURATION == &quot;DebugConfigurable&quot; ]; then</pre><pre>echo &quot;setting bundle is required&quot;</pre><pre>elif [ $CONFIGURATION == &quot;ReleaseConfigurable&quot; ]; then</pre><pre>echo &quot;setting bundle is required&quot;</pre><pre>else</pre><pre>echo &quot;settings bundle is not required&quot;</pre><pre>rm -rf &quot;$BUILD_APP_DIR/Settings.bundle&quot;</pre><pre>fi</pre><p><strong>What does this script do? </strong>If current build configuration used by selected scheme is either DebugConfigurable or ReleaseConfigurable then it do nothing else it removes the setting bundle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcYkVLVD7HpQfZzWER2mXA.png" /></figure><p>Now, try running the app. Setting bundle would not be there if you select scheme other than DemoApp(Configurable).</p><h3>What’s need to be taken care of?</h3><p>This is just a demo project. You need to take care of certain points like on switching the server from app settings you need to logout from previous server and re-initialising network service with latest pointing server.</p><p>Also, you may request QA, if they want to switch the server, they should delete the app , then after re-installing the app, select the server from app settings and test on desired server.</p><h3>What you achieved as developer?</h3><p>By putting this one time effort, you save <strong>TIME </strong>consumed in creating and distributing multiple builds which have only one difference <strong>the pointed server</strong>.</p><p><strong>Sample project</strong></p><p>You may refer this github repo for sample project:</p><p><a href="https://github.com/AnmolSuneja/MultiServerBuild">AnmolSuneja/MultiServerBuild</a></p><p>I hope this helps someone!! Please clap if you like the article. Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e48460df18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/distributing-configurable-ios-app-for-multiple-servers-using-configurations-schemes-and-settings-2e48460df18">Distributing configurable iOS app for multiple servers using configurations, schemes and settings…</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>