Issue with Firebase Firestore?

So I currently have a Firebase Firestore. That isn't necessarily what I need help with. The Firestore is set up correctly. The issue I am having is, I keep getting an error saying "Thread 1: "Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore"". Even though I am calling FirebaseApp.configure() before using Firestore. In fact, it's the first thing my app does when it runs. Anyone have any solutions? Here is the code in my @main file:

import UserNotifications
import FirebaseCore
import FirebaseFirestore
import SwiftUI

class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?

  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    // Firebase configuration
    // FirebaseApp.configure()

    // Notification setup
    UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { granted, _ in
      guard granted else { return }

      DispatchQueue.main.async {
        application.registerForRemoteNotifications()
      }
    }

    return true
  }
}

@main
struct MyApp: App {
    
    init() {
        FirebaseApp.configure()
    }
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    @Environment(\.colorScheme) var colorScheme
    
    let myData = MyData()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(myData)
                .background(colorScheme == .dark ? Color.black : Color.white)
                .foregroundColor(colorScheme == .dark ? Color.white : Color.black)
                //.background(Color(red: 0.956, green: 1, blue: 1))
        }
    }
}

And here is my code in the ContentView file (this is where I am getting the error):

import FirebaseFirestore
import FirebaseCore

class MyData : ObservableObject {
    @Published var selectedTab : Int = 1
    @Published var selectedView : ContentView.Views = .selectView
    @Published var selectedLawyer : ContentView.Lawyers = .selectLawyer
    @Published var selectedAgent : ContentView.Agents = .selectAgent
    @Published var selectedState : FiltersView.States = .selectState
    @Published var selectedStatus : ProfileView.Status = .looking
    @Published var isShowingProfile = false
    @Published var isShowingFilters = false
    @Published var isShowingSettings = false
    @Published var allowLoanOfficers = false
    @Published var allowFinancialAdvisors = false
    @Published var allowDivorceLawyers = false
    @Published var allowCriminalLawyers = false
    @Published var allowPersonalInjuryLawyers = false
    @Published var allowCivilLawyers = false
    @Published var allowCorporateLawyers = false
    @Published var allowTaxLawyers = false
    @Published var allowBusinessLawyers = false
    @Published var allowFinancialLawyers = false
    @Published var allowInsuranceLawyers = false
    @Published var allowEstateLawyers = false
    @Published var allowMedicalMalpracticeLawyers = false
    @Published var allowContractLawyers = false
    @Published var allowRealEstateLawyers = false
    @Published var allowRealEstateAgents = false
    @Published var allowIndividualSellers = false
    @Published var allowHealthInsuranceAgents = false
    @Published var allowAutoInsuranceAgents = false
    @Published var allowCommercialBrokers = false
    @Published var allowMortgageLenders = false
    @Published var allowMechanics = false
    @Published var name = "Please Add Name"
    @Published var filterCity = ""
    @Published var filterZip = 0
    var filterZipString: String {  // Computed property to get and set as String
            get { "\(filterZip)" }
            set {
                // Ensuring only numbers are accepted and updating the Int value
                if let number = Int(newValue.filter { "0123456789".contains($0) }) {
                    filterZip = number
                }
            }
        }
    @Published var myLoanOfficers = 1
    @Published var myFinancialAdvisors = 1
    @Published var myDivorceLawyers = 1
    @Published var myCriminalLawyers = 2
    @Published var myPersonalInjuryLawyers = 1
    @Published var myCivilLawyers = 1
    @Published var myCorporateLawyers = 5
    @Published var myTaxLawyers = 1
    @Published var myBusinessLawyers = 2
    @Published var myFinancialLawyers = 1
    @Published var myInsuranceLawyers = 1
    @Published var myEstateLawyers = 1
    @Published var myMedicalMalpracticeLawyers = 1
    @Published var myContractLawyers = 1
    @Published var myRealEstateLawyers = 1
    @Published var myRealEstateAgents = 2
    @Published var myHealthInsuranceAgents = 1
    @Published var myAutoInsuranceAgents = 1
    @Published var myMechanics = 1
    @Published var firstMyAgentTabOpen = true
    @Published var allowAutoCollapse = false
    @Published var isShowingLoanOfficers = false
    @Published var isShowingFinancialAdvisors = false
    @Published var isShowingDivorceLawyers = false
    @Published var isShowingCriminalLawyers = false
    @Published var isShowingPersonalInjuryLawyers = false
    @Published var isShowingCivilLawyers = false
    @Published var isShowingCorporateLawyers = false
    @Published var isShowingTaxLawyers = false
    @Published var isShowingBusinessLawyers = false
    @Published var isShowingFinancialLawyers = false
    @Published var isShowingInsuranceLawyers = false
    @Published var isShowingEstateLawyers = false
    @Published var isShowingMedicalMalpracticeLawyers = false
    @Published var isShowingContractLawyers = false
    @Published var isShowingRealEstateLawyers = false
    @Published var isShowingRealEstateAgents = false
    @Published var isShowingHealthInsuranceAgents = false
    @Published var isShowingAutoInsuranceAgents = false
    @Published var isShowingMechanics = false
    @Published var search = ""
    @Published var myAgentView = false
    @Published var messageSearch = ""
    @Published var selectedColor = Color.purple
    @Published var isShowingPurchases = false
    @Published var isShowingMonthlyPrices = true
    @Published var planType = "Plus"
    @Published var basicPrice = 29.99
    @Published var plusPrice = 39.99
    @Published var premiumPrice = 49.99
    @Published var boostAmount = 1
    @Published var oneBoost = 9.99
    @Published var fiveBoosts = 37.49
    @Published var tenBoosts = 49.99
    
    private lazy var db = Firestore.firestore()
    
    init() {
        fetchInitialData()
    }
    
    private func fetchInitialData() {
    }
}

Anyone know any solutions? I have tried everything I can think of to get it to work.

Hello, I found the solution to the problem, you have to initialize it using this code in your main struct.

` class FirebaseInitializer {
        init() {
            FirebaseApp.configure()
        }
    }

    let firebaseInit = FirebaseInitializer()`
Issue with Firebase Firestore?
 
 
Q