I think you need to make your viewModel object either @StateObject or @ObservedObject first and then inside your viewModel class make the property @Published to get updates on View.
struct InAppPurchaseView: View {
@StateObject var viewModel = InAppPurchaseViewModel()
var body: some View {
VStack {
if !viewModel.currentProgressInfo.isEmpty {
Text(viewModel.currentProgressInfo)
} else {
Button() //and a few more buttons that calls actions to the viewModel
}
}
}
}
@Observable
class InAppPurchaseViewModel: TransactionObserverDelegate {
@Published var currentProgressInfo = ""
//here is a lot of code that update currentProgressInfo, sometimes it is "" and sometimes "You did sth here".
}