Upon moving a view and it's ViewModel(where i am using Firestore) from the main app module to it's own module, my Canvas Previews crash with the error:
XCPreviewAgent crashed due to an uncaught exception
FIRIllegalStateException. Reason: Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore
The FirebaseApp Instance is configured in the AppDelegate:
import Firebase
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
}
I have tried using Firestore in a function in the ViewModel but still crashing.
public struct AuthContentView: View {
@StateObject private var vm = ViewModel()
public init() {}
public var body: some View {
VStack(spacing: 24) {
Text("AuthContentView")
Button("TapMe") {
Task {
await fetchData()
}
}
.buttonStyle(.bordered)
}
}
@Sendable
func fetchData() async {
await vm.fetchData()
}
}
extension AuthContentView {
@MainActor
final class ViewModel: ObservableObject {
func getFirestoreInstance() -> Firestore {
Firestore.firestore()
}
func fetchData() async {
let docSnap = try? await getFirestoreInstance().document("users").getDocument()
}
}
}
I have also tried configuring the FirebaseApp Instance in a dedicated Firebase module where I have conformance to protocols in Core/Domain module that allows other modules interact with the dedicated Firebase module, but the FirebaseApp.configure() cannot see the GoogleService-info.plist file which sits in the core module.
Any help is highly appreciated

ObservableObjectstructured, you callFirestore.firestore()every time you callfetchData(), and at the same time you already haveFirebaseApp.configure()in yourclass AppDelegate. It would be easier just to have your Appinit(){FirebaseApp.configure()}. If Xcode does not have the libraries in your project, add them manually to the target. It is also not clear why you are usingfinal class ViewModel: ObservableObjectsince you don't have any@Published var .... Note, you could simply useButton("TapMe") { await vm.fetchData() }.