Skip to content

Instantly share code, notes, and snippets.

@clayellis
Last active January 22, 2018 17:09
Show Gist options
  • Save clayellis/86adfd2026b1314e7eabd2cba271ead4 to your computer and use it in GitHub Desktop.
Save clayellis/86adfd2026b1314e7eabd2cba271ead4 to your computer and use it in GitHub Desktop.
A scrappy step-by-step to creating multiple configurations for an iOS target
  1. Create a Production.xcconfig and a Development.xcconfig file (or whatever you want to call them)
  2. 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]
  1. In the Project Navigator select the Project (not a Target) > Info > Configurations > + “Duplicate Debug” > Rename to “Development Debug”
  2. Rename “Debug” -> “Production Debug”, “Release” -> “Production Release” (You should have three configurations: Production Debug, Production Release, Development Debug)
  3. 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)
  4. In the Project Navigator select the main Target > Build Settings > Product Name > Set to $(PRODUCT_NAME)
  5. Target > Build Settings > Product Bundle Identifier > Set to $(BUNDLE_IDENTIFIER)
  6. In your Info.plist create two entries:
  • API Scheme = ${API_SCHEME}
  • API Host = ${API_HOST}
  1. 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
}()
  1. (In the menu bar) Product > Scheme > Manage Schemes
  2. Select the default scheme, then click the gear in the bottom left > “Duplicate” and rename to “App - Development”
  3. Rename the original “App - Production”
  4. 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment