I did not have this issue in Xcode version 14.2, but I am getting it in Xcode 14.3. I added all of the Firebase packages and I know that FirebaseFirestore is, in fact, part of the package.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
The line with the comment below has the error and says the error I am receiving. If you need to see anything else, do not hesitate to ask. I'd be happy to provide it.
struct ContentView: View {
@EnvironmentObject var myData: MyData
@EnvironmentObject var userViewModel: UserViewModel
var body: some View {
VStack {
NavigationSplitView {
List {
NavigationLink {
MainApp()
.navigationTitle ("Counter")
} label: {
HStack {
Text("Counter")
.font(.largeTitle)
.foregroundColor(Color.red)
Spacer()
Image(systemName: "plus.forwardslash.minus")
.font(.largeTitle)
.foregroundColor(Color.red)
.onTapGesture {
myData.totalLeft = myData.total - myData.counter
}
}
}
NavigationLink {
Settings()
.navigationTitle("Settings")
} label: {
HStack {
Text("Settings")
.font(.largeTitle)
.foregroundColor(Color.red)
Spacer()
Image(systemName: "gear")
.font(.largeTitle)
.foregroundColor(Color.red)
}
}
NavigationLink {
Metrics()
.navigationTitle("Metrics")
} label: {
HStack {
Text("Metrics")
.font(.largeTitle)
.foregroundColor(Color.red)
Spacer()
Image(systemName: "chart.bar")
.font(.largeTitle)
.foregroundColor(Color.red)
}
}
NavigationLink {
ProfileView()
.navigationTitle ("Account")
.environmentObject(userViewModel) //Thread 1: Fatal error: No ObservableObject of type UserViewModel found. A View.environmentObject(_:) for UserViewModel may be missing as an ancestor of this view.
} label: {
HStack {
Text("Account")
.font(.largeTitle)
.foregroundColor(Color.red)
Spacer()
Image(systemName: "person")
.font(.largeTitle)
.foregroundColor(Color.red)
}
}
}
} detail: {
Text("Select a Page")
}
}
.environmentObject(userViewModel)
}
}
import Foundation
import FirebaseAuth
import FirebaseFirestore
import FirebaseFirestoreSwift
class UserViewModel: ObservableObject {
@Published var user: User?
private let auth = Auth.auth()
private let db = Firestore.firestore()
var uuid: String? {
auth.currentUser?.uid
}
var userIsAuthenticated: Bool {
auth.currentUser != nil
}
var userIsAuthenticatedAndSynced: Bool {
user != nil && userIsAuthenticated
}
private func sync() {
guard userIsAuthenticated else { return }
let docRef = db.collection("users").document(self.uuid!)
docRef.getDocument { (document, error) in
guard let document = document, document.exists, error == nil else {
print("Error retrieving document: \(error!)")
return
}
do {
let data = document.data()
let jsonData = try JSONSerialization.data(withJSONObject: data as Any, options: .prettyPrinted)
let user = try JSONDecoder().decode(User.self, from: jsonData)
self.user = user
} catch {
print("Sync error: \(error)")
}
}
}
private func add (_ user: User) {
guard userIsAuthenticated else { return }
do {
let userData = try JSONSerialization.jsonObject(with: try JSONEncoder().encode(user), options: []) as? [String: Any]
let _ = try db.collection("users").document(self.uuid!).setData(userData ?? [:])
} catch {
print("Error adding: \(error)")
}
}
private func update() {
guard userIsAuthenticatedAndSynced else { return }
do {
let userData = try JSONSerialization.jsonObject(with: try JSONEncoder().encode(user), options: []) as? [String: Any]
let _ = try db.collection("users").document(self.uuid!).setData(userData ?? [:])
} catch {
print("Error updating: \(error)")
}
}
}
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var userViewModel = UserViewModel()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(MyData())
.environmentObject(userViewModel)
}
}
}
Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure
I am getting the error in the title on the following form. Cannot figure out why. Please help! I do not have any custom style for forms or anything. Also getting an info bubble on the line as well that says "'init(_:)' declared here (SwiftUI.Form)"
Form {
Section(header: Text("Employee Name")) {
TextField("First Name", text: $user.user?.firstName ?? "")
TextField("Last Name", text: $user.user?.lastName)
}
Section(header: Text("Employee and Store Info")) {
TextField("Store Number", text: Int($user.user?.storeNumber))
.keyboardType(.numberPad)
TextField("Team Member Number", text: Int($user.user?.teamMemberNumber))
}
}
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.
I am trying to release a beta version of an app for internal TestFlight testing but I keep getting a notification saying it has invalid binary. I have tried looking this up but I can't find anything that helps. Please help! If you need anything in addition to this, let me know. I just wasn't sure what to share.