ios – Easy methods to present/Disguise view on API response in swiftui?

[ad_1]

I’m making an attempt to point out the view on a situation however the information is coming from the API so the code executed earlier than the API response however I need to run the code after API response, how can I do this in swiftUI app?

class DashboardViewModel: ObservableObject {
    
    var poCount:[TaskCount]?
    
    @State var totalApprovalCount = 0



func getData() {

    APIService.shared.makeApiTypeRequest(url: APIURLConstant.poTaskCountUrl, param: nil, methodType: .get, anticipating: [TaskCount].self, passToken: true) { lead to
                swap consequence {
                case .success(let respData):
                    DispatchQueue.principal.async {
                        self.rcCount = respData
                        print("fetchRCCount referred to as (respData.rely)")
                        if respData.rely > 0 {
                            self.totalApprovalCount += respData[0].rely ?? 0
                        }
                        
                        if respData.rely > 1 {
                            self.totalApprovalCount += respData[1].rely ?? 0
                        }
                    }
                case .failure(let error):
                    if error as! CustomError == CustomError.tokenExpired {
                        DispatchQueue.principal.async {
                            
                        }
                    }
                }
            }

}

view:

struct DashboardCombinedView: View {
    @ObservedObject var dashboardModel = DashboardViewModel()
    var physique: some View {
        VStack {
            
            if dashboardModel.totalApprovalCount > 0 {
                Textual content("My customized view")
            }
      }.onAppear(){
        dashboardModel.getData()
      }
}

the situation if dashboardModel.totalApprovalCount > 0 { is all the time will get false because it relies on the API response, how can I verify this situation after API name?

[ad_2]

Leave a Reply