79542813

Date: 2025-03-29 05:11:34
Score: 1
Natty:
Report link

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".
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @StateObject
  • User mentioned (0): @ObservedObject
  • User mentioned (0): @Published
  • Low reputation (1):
Posted by: user30099620