I have class getDataFromDatabase
which has func readData()
thats read data from Firebase.
class getDataFromDatabase : ObservableObject {
So the problem is in your completion handler. It returns before you retrieve the data.
Solution is to make your arrays @Published and read the data in real time from the view. You have to remove the completion handler.
Call the function on ‚onAppear()‘ and use @ObservedObject to bind to your ViewModel (getDataFromDatabase). This is how it’s done in SwiftUI.
Please capitalize the first letter and use something more generic like „YouViewName“ViewModel.
Your name is fine for a method/function but not for a Class