Browse Questions
Select the correct GoogleService-Info.plist at launch based on the active build configuration:
import SwiftUI
import FirebaseCore
enum AppEnvironment { case dev, sit, uat, prod }
@main
struct YourApp: App {
init() {
configureFirebase()
}
var body: some Scene {
WindowGroup {
NavigationStack { RootView() }
}
}
private var currentEnvironment: AppEnvironment {
#if Dev
return .dev
#elseif SIT
return .sit
#elseif UAT
return .uat
#else
return .prod
#endif
}
private func configureFirebase() {
let plistName: String
switch currentEnvironment {
case .dev: plistName = "GoogleService-Info-Dev"
case .sit: plistName = "GoogleService-Info-SIT"
case .uat: plistName = "GoogleService-Info-UAT"
case .prod: plistName = "GoogleService-Info"
}
guard let filePath = Bundle.main.path(forResource: plistName, ofType: "plist") else {
fatalError("❌ Could not find plist file: \(plistName).plist")
}
guard let options = FirebaseOptions(contentsOfFile: filePath) else {
fatalError("❌ Could not load Firebase options from: \(plistName).plist")
}
FirebaseApp.configure(options: options)
print("✅ Firebase configured for \(currentEnvironment) — Bundle ID: \(options.bundleID)")
}
}
The fatalError guards are intentional — a misconfigured Firebase setup should fail loudly at launch during development, not silently at runtime.