0

I made the front end of an application but now I have to make the back end and therefore print a DB the problem is that I have an error "Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore" :

App delegate :

class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { FirebaseApp.configure() return true } } 

DataBase :

struct New: Identifiable { var id: String = UUID().uuidString var news: String } class NewsViewModel: ObservableObject { @Published var news = [New]() private var db = Firestore.firestore() func fetchDate() { db.collection("News").addSnapshotListener { (querySnapshot, error) in guard let documents = querySnapshot?.documents else { print("No documents") return } self.news = documents.map { (QueryDocumentSnapshot) -> New in let data = QueryDocumentSnapshot.data() let news = data["News"] as? String ?? "ya r" return New(news: news) } } } } 

Print DB :

 NavigationView { List(viewModel.news) { news in VStack(alignment: .leading) { Text(news.news) } .navigationTitle("News") } } .onAppear() { self.viewModel.fetchDate() } 

Thanks for help

0

1 Answer 1

0

Can you add it inside willFinishLaunchingWithOptions

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { FirebaseApp.configure() return true } 
Sign up to request clarification or add additional context in comments.

2 Comments

or should I add this?
I tried to put it in place of my appdelagte but I always get the same error

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.