Wednesday, October 7, 2026
HomeiOS Developmentios - SwiftUI Easy methods to present a view primarily based on...

ios – SwiftUI Easy methods to present a view primarily based on worth from api name in father or mother view

[ad_1]

I’m creating an OTP Verification Web page which is having a OTPDigitField() inside one VSTack as a baby View.

THe OTP Verification web page (father or mother)has an API Name . Upon failure of which the digit fields ought to flip pink and the pink error textual content ought to show below otps.

My query is initally the showError is not going to be true and the error textual content will present up . How can I passs the values from apicall to little one view efficiently?
An instance might be :

MobileVerification.swift :

 View {
  VStack {

    //Different View Components

    OTPDigitField { code, standing in
      if SubmitClicked && apiCallStstatus() {
        errorStatus(true)
      } else {
        errorStatus(false)
      }
    }
  }
}

OTPDigitField.swift

var handler: (String(Bool) -> Void) -> Void
@State non-public var showError: Bool = false // Right here initally its false inflicting error to look in inital loading itself

View {
  //code for digits subject
  //code for error
  .hidden(showError)
  func validate() {
    handler(digits) { success in
      if success && !code.isEmpty {
        showError = true
      }
    }
  }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments