SoatDev IT Consulting
SoatDev IT Consulting
  • About us
  • Expertise
  • Services
  • How it works
  • Contact Us
  • News
  • October 2, 2023
  • Rss Fetcher

Power of Xcconfigs in Xcode

Photo by Avinash Murugappan on Unsplash

So this isn’t just a tutorial on how to use configuration files in Xcode; it also talks about the emotion behind improving and using xcconfig files. This idea hit me when I had to make clones of my project. So why should you create a new project when we have GOD’s gift in our hands’ configuration files, amigos?

For those who don’t know about configuration files, read about it in my previous article:

Using .xcconfig files to store various SDK keys and IDs inside Xcode Project.

Now, let’s start by creating a project called GodsGift. Install one or two pods to your project because most require third-party help. If you don’t need it, it’s icing on the cake, and you can declare yourself the Supreme Power.

If you’ve installed your pods in any of your projects, open their workspace file. If your project doesn’t require any external pods, open your xcodeproj file, and you’ll see two default configurations, i.e., Debug and Release. These are shown below:

In the image above, you can see that Pods-GodsGift.debug is connected to the Debug configuration, and Pods-GodsGift.release is connected to the Release configuration. Now we can create two configurations in each project, Development and Production, rename the default Debug Release to the Project name, and add new files via the + button in Configurations.

Project1 and Project2 are shown in the above image; they’re made with the development and production configurations. But all of the development and production is linked to the same type of .xcconfig files: Pods-xxxxxxxx.xxxx. So now, we’ll manually create four .xcconfig files related to our projects.

Here are the files we just created:

Now, use these files in your Xcode project’s configurations as shown below:

All manually created .xcconfigs are selected in the Configurations section.

Now, build your project.

Uh-oh. Your project got an error related to Pods-xxxxxxx.xcfilelist.

So, knowing this, we need to import our Pods’ debug and release xcfilelist into our manually generated .xcconfig files. This is recommended whenever you create new xcconfig files.

First, uninstall the pods, then reinstall them. A new xcfilelist will be created; it’s related to the xcconfig file used in the configuration we imported inside the four xcconfig files we created earlier.

Now, we’re done importing the red-marked files into our green-marked files. The yellow areas in the above image can help you see this.

Use this code to add these files to the xcconfig files you created manually:

#include "Pods/Target Support Files/Pods-PROJECT_NAME/Pods-PODS_XCONFIG_NAME.xcconfig"

Now that your error related to Pods-xxxxxxx.xcfilelist is gone, you can run and try it.

Inside of your xcconfig files, you can put anything like BundleId, Version, Build Version, BasePath, FacebookID, Google Plist file name, any SDK keys, APP_ICON asset name, and Launch Screen Name that is different for each app.

And you can use these things dynamically in the Project Build Settings by setting the $(XCCONFIG_KEY), so now if you change anything in the xcconfig file, it will be changed in the app also. After using the xcconfig files, don’t you dare change these things manually from Xcode. Change these things from xcconfig files only. Otherwise, your work will go to crap because of a single mistake, Ha, ha!

So, do it carefully!

Let’s create some temporary keys inside the xcconfig files.

As you see in the above file, we created all the required keys to use Build settings with $(KEY) to use these things, and you are just done with these things.

Now, the last step is to create schemes via manage schemes for each Configuration to use.

Create four schemes dev prod for each project, i.e., Project1 and Project2. This will result in four schemes using containers in the GodsGift project.

OK, the schemes are done now. Just double-click on each scheme to select its configuration for Debugging, Archiving, Test, Run, Analyze, etc. Please make sure you assign the correct configs and watch out.

Now you can switch your projects easily while debugging, running, archiving, etc.

If you want to access any configuration value inside your Swift code, one more step is to add these keys to your plist file with the following code:

<key>KEY</key>
<string>$(KEY)</string>

Use this code to access these key values via plist:

e.g., let appName = Configuration.getValue(for: .APP_APP_NAME)

Thanks for reading this. Try and implement it in your project. If any issues occur, feel free to reach out to me in the comments.

Happy coding. Love what you do and feel it 😍😍😍.


Power of .xcconfigs in Xcode was originally published in Better Programming on Medium, where people are continuing the conversation by highlighting and responding to this story.

Previous Post
Next Post

Recent Posts

  • Winning capital for your AI startup? Kleida Martiro is leading the conversation at TechCrunch All Stage
  • Nothing releases its first over-the-ear headphones, the $299 Headphone (1)
  • The electric Hummer is almost outselling the F-150 Lightning
  • Nothing releases their first over-the-ear headphones
  • Nothing launches its most expensive flagship yet, Phone (3)

Categories

  • Industry News
  • Programming
  • RSS Fetched Articles
  • Uncategorized

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023

Tap into the power of Microservices, MVC Architecture, Cloud, Containers, UML, and Scrum methodologies to bolster your project planning, execution, and application development processes.

Solutions

  • IT Consultation
  • Agile Transformation
  • Software Development
  • DevOps & CI/CD

Regions Covered

  • Montreal
  • New York
  • Paris
  • Mauritius
  • Abidjan
  • Dakar

Subscribe to Newsletter

Join our monthly newsletter subscribers to get the latest news and insights.

© Copyright 2023. All Rights Reserved by Soatdev IT Consulting Inc.