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

Sandeep Kumar
3 min readJan 3, 2019

If you all are familiar with integrating Facebook SignIn SDK or GoogleSignIn SDK and other SDKs with their iOS Applications in Xcode.

Let’s take an example of integrating Facebook SDK for signup and login procedure. So first you have signup for developer account on and follow all instructions given on https://developers.facebook.com/docs/facebook-login/ios/ to get Facebook AppID which you have to store in your Info.plist file.

It’s OK to save directly in plist.

Incase of Facebook and Google Login integration you have to also add URL Types in project target -> Info.

what if one day come you have to change these development keys, IDs, Secret IDs, ClientIds, RevereClientIds etc for a project. Then you have to change these things in multiple places like info.plist, URL Types in Info of project target and in .swift files in some cases.

So here is the solution if you want to manage these things in only one place.

Create two files with .xconfig extensions inside project named Release.xcconfig and Debug.xcconfig and write all your keys, ReverseClientIds, ClientIds etc of various SDKs in both files like below.

Now you can access these via following syntax inside plist and URL types of Project Target -> Info

$(PROJECT_NAME_GOOGLE_SIGNIN_CLIENT_ID)

Now your Info.plist will appear like these.

same repeat inside URL Types (Project Target -> Info)

If you want to access .xcconfig any key or value inside .swift file. Like incase of Google SignIn you have to access Google Client ID in following code

GIDSignIn.sharedInstance()?.clientID = xxxxxxxxxxxx

Then you can’t access value directly from .xconfig file but you can access from Info.plist file. so please first make sure it’ll be added inside Info.plist

In our case it’s added in above image by name GOOGLE_CLIENT_ID.

so for accessing this from Info.plist write the following code.

let googleClientID = (Bundle.main.infoDictionary?[“GOOGLE_CLIENT_ID”] as? String)?

.replacingOccurrences(of: “\\”, with: “”)

One more thing if you have installed Facebook SDK, GoogleSDK or any other SDK then you could find two .xcconfig files in your xcode project already with following naming convention.

Pods-PROJECT_NAME.debug.xcconfig

Pods-PROJECT_NAME.release.xcconfig

So you have import or include these files inside your Release.xcconfig and Debug.xcconfig files respectively.

Write following inside Release.xcconfig on first line.

#include “Pods/Target Support Files/Pods-PROJECT_NAME/Pods-PROJECT_NAME.release.xcconfig”

Inside Debug.xcconfig write this.

#include “Pods/Target Support Files/Pods-PROJECT_NAME/Pods-PROJECT_NAME.debug.xcconfig”

Now you have to complete your last step.

Goto project navigator-> Info -> Configurations

and change Red marked xcconfig files with you created files like given below.

Now you have all your Keys, ClientIDs etc all in one place. You can change these anytime in Release.xconfig and Debug.xcconfig files.

Happy Coding: — — — — — — ) Peace Guys 👋 👋👋

Do 👏 👏 👏 if you find it beneficial.

--

--