
Open XCode and create a new single view application with a proper name.
Before adding a schema, we need to know that every XCode schema comes with two different build configurations: Debug and Release. Then if we want, we can make changes specific to a particular build configuration.
Now to add our build configurations, select the project in the Project Navigator pane on the left. Then select Info from the two options (Info and Build Settings). In the Configurations, we have to add our own configuration for the five environments (Development, Production, QA, Beta, and UAT) there.



Right click on Project, select new file, then add Configuration Settings File and give it the same name as the environment.


Rename the info.plist file as development.plist. Copy and paste the same plist file for the different environments inside the project, and rename each of the plist file with the environment’s name. You can set some environment-specific keys and values in the plist files. After that, add the keys from the configuration file to the plist files like this:

Select all the build configurations (Debug and Release) in Projects Info one by one. Then set the appropriate configuration file, which you have added to the project.


Now the last step is linking the schema with the build configuration. To do this, select any schema, go to edit schema, and set the appropriate build configuration there.
Now all the set up is done. The only thing you have to do select the schema and run — the environment will be automatically selected for you. So for fetching the server URL and other values, I have created an Environment.swift file. Check it out:
import Foundation
public enum PlistKey {
case ServerURL
case ConnectionProtocol
func value() -> String {
switch self {
case .ServerURL:
return "server_url"
case .ConnectionProtocol:
return "protocol"
}
}
}
public struct Environment {
fileprivate var infoDict: [String: Any] {
get {
if let dict = Bundle.main.infoDictionary {
return dict
}else {
fatalError("Plist file not found")
}
}
}
public func configuration(_ key: PlistKey) -> String {
switch key {
case .ServerURL:
return infoDict[PlistKey.ServerURL.value()] as! String
case .ConnectionProtocol:
return infoDict[PlistKey.ConnectionProtocol.value()] as! String
}
}
}To fetch the server URL or other settings in ViewController.Swift or any other file, you have to write only one line of code:
let server_url = Environment().configuration(PlistKey.ServerURL)
print(server_url)You can also manage different app icons for different environments from build settings. Then, you will only have to look for a second to see which environment build is installed on your device.



