new to swiftui and firestore and struggling with calling this document array. Hoping someone can help me out with the code to call the "items" array into a VStack.
Added code I've been trying
View Model
import SwiftUI
import FirebaseFirestore
class MovieItemViewModel: ObservableObject {
@Published var movieItems = [MovieItem]()
private var db = Firestore.firestore()
func fetchData() {
db.collection("movies").order(by: "items").addSnapshotListener { (querySnapshot, error) in
guard let documents = querySnapshot?.documents else {
print("No Documents")
return
}
self.movieItems = documents.map { (queryDocumentSnapshot) -> MovieItem in
let data = queryDocumentSnapshot.data()
let items = data["items"] as? String ?? ""
return MovieItem(item: items)
}
}
}
}
Model
import SwiftUI
struct MovieItem: Identifiable {
var id: String = UUID().uuidString
var item: String
}
Main View
struct MovieDetailListView: View {
@ObservedObject private var viewModel = MovieItemViewModel()
var body: some View {
VStack(alignment: .leading, spacing: 15){
ForEach(viewModel.movieItems.indices, id: \.self) { i in
Text(viewModel.movieItems[i].item)
}
}
.onAppear() { self.viewModel.fetchData() }
}
}

Value of type 'MovieItem' has no member 'name', and on the return in the viewmodel i getArgument passed to call that takes no argumentsviewModelMovieItemViewModeldoesn't have a propertyitemsso you can't doForEach(viewModel.items.…. You called itmovieItems, soForEach(viewModel.movieItems.…? 2. YourMovieItemdoesn't have a propertyname, so you can't doText(viewModel.items[i].name).print(self.viewModel.fetchData())in the onAppear but the console is just printing "()"