Browse Questions
  • An .xcconfig file is a plain text file that sets build settings.
  • Encapsulation, abstraction, inheritance, and polymorphism.
  • Inject dependencies through init using protocols.
  • All three transform collections but handle the results differently.

Answer: An .xcconfig file is a plain text file that sets build settings. It's useful for managing different configurations (Dev, Staging, Production) without duplicating targets.

Example file — Debug.xcconfig:

// Debug.xcconfig
API_BASE_URL = https://dev.api.com
ANALYTICS_KEY = dev_key_123
BUNDLE_ID_SUFFIX = .debug

// Override bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = com.myapp$(BUNDLE_ID_SUFFIX)

Accessing in Swift:

// Add keys to Info.plist first:
// <key>API_BASE_URL</key>
// <string>$(API_BASE_URL)</string>

let apiURL = Bundle.main.infoDictionary?["API_BASE_URL"] as? String ?? ""

Why use xcconfig over hardcoded values:

  • Keep secrets out of source code
  • Different API endpoints per environment
  • One place to change a value that affects multiple targets
  • Works well with CI/CD — inject values at build time