- Create a
Production.xcconfig and a Development.xcconfig file (or whatever you want to call them)
- In both of those config files:
(production) [development]
BUNDLE_IDENTIFIER = (com.company.ios) [com.company.ios.dev]
PRODUCT_NAME = (App) [App Dev]
API_SCHEME = (https) [https]
API_HOST = (api.company.com) [dev.company.com]
- In the Project Navigator select the Project (not a Target) > Info > Configurations > + “Duplicate Debug” > Rename to “Development Debug”
- Rename
“Debug” -> “Production Debug”, “Release” -> “Production Release”
(You should have three configurations: Production Debug, Production Release, Development Debug)
- On each of those configurations, expand them so you can see the targets, then under “Based on Configuration File” column select the corresponding
.xcconfig file (either Production or Development)
- In the Project Navigator select the main Target > Build Settings > Product Name > Set to
$(PRODUCT_NAME)
- Target > Build Settings > Product Bundle Identifier > Set to
$(BUNDLE_IDENTIFIER)
- In your
Info.plist create two entries:
API Scheme = ${API_SCHEME}
API Host = ${API_HOST}
- Then you can pull the
baseURL out of the .xcconfig file via the Info.plist dictionary:
lazy var apiBaseURL: URL = {
let schemeString = Bundle.main.infoDictionary["API Scheme"] as! String
let apiHostString = Bundle.main.infoDictionary["API Host"] as! String
var apiURLComponents = URLComponents()
apiURLComponents.scheme = schemeString
apiURLComponents.host = apiHostString
guard let apiBaseURL = apiURLComponents.url else {
// Handle this error
}
return apiBaseURL
}()
- (In the menu bar) Product > Scheme > Manage Schemes
- Select the default scheme, then click the gear in the bottom left > “Duplicate” and rename to
“App - Development”
- Rename the original
“App - Production”
- Open the each scheme (double click it), and for each action (Run, Test, Profile, Analyze, Archive) go to the Info tab and select the appropriate Build Configuration:
(production) [development]
- Run:
(Production Debug) [Development Debug]
- Test:
(Production Debug) [Development Debug]
- Profile:
(Production Release) [Development Debug]
- Analyze:
(Production Debug) [Development Debug]
- Archive:
(Production Release) [Development Debug]
(You should now have two schemes: App - Production, App - Development. And at this point you should be able to install both on a single device)