I have an application that is:
The first view is a list of stores (the list has been read from Firebase successfully) because there is a (List)
The second view is the store details (here, I couldn't read the data from Firebase)
@ObservedObject var viewModel = StoreViewModel() var body: some View { ScrollView { VStack { Text(viewModel.stores.name)}} How read this data from Firebase ?
class StoreViewModel: ObservableObject { @Published var stores = [StoreView]() private var db = Firestore.firestore() func fetchData() { db.collection("Stores").addSnapshotListener{(querySnapshot, error)in guard let documents = querySnapshot?.documents else { print("No documents in Firebease") return } self.stores = documents.compactMap { queryDocumentSnapshot -> StoreView? in return try? queryDocumentSnapshot.data(as: StoreView.self) } } } }
ForEachhere?Text(viewModel.store.name)because there is no propertystoreon your view model. It looks like you're already clear on how to use theList, as what you said in your comment looks fine.