how to perform Condition check, before segue unwind

VC1 segues to VC3 which has a keypad and predetermined lowest number acceptable entered into a label. User can either add a number to the end of this string or delete a number. When “Accept” key is pressed, the string.toInt() is passed to VC1 and segue is unwind via

@IBAction func unwindToSegue(segue: UIStoryboardSegue, sender:UIStoryboardSegue){
    BetLabels[betSourceR].text = BetReturned
    if BetReturned == ""{} else{
        Chip[betSourceR].hidden = false}}

I need to achieve so that no string.toInt() lower than minimum is accepted and some sort of override func that stops the unwind from happening while posting a warning to the user that this input is not acceptable.

  • Decompilation possibilities in iOS and how to prevent them
  • Search Array of Dictionaries for Value in Swift
  • Presenting a view controller programmatically in swift
  • When I clean Xcode DerivedData I can't run my app in iOS Simulator
  • Swift struct adopting protocol with static read-write property doesn't conform?
  • UITableView : viewForHeaderInSection: not called during reloadData:
  • How would i achieve this when?
    Maybe place something in VC3 func prepareForsegue? Or another method?

    Or could i disconnect the “accept” from the unwind, and make a IBAction that if under minimum{ warn user, return to VC3} else {VC1.unwindToSegue}

    2 Solutions Collect From Internet About “how to perform Condition check, before segue unwind”

    To achieve this, connect Controller of VC3 to its own exit and select the unwind action.

    Give this exit-segue a segue.identifier “YOUR EXIT TEXT”

    Still in VC3, create an IBAction for the “Accept” button.

    @IBAction func accept(sender: AnyObject) {
        if //Condition X is true
            {performSegueWithIdentifier("YOUR EXIT TEXT", sender: self)}
        else {
            //Do this
            }
    

    I found a good answer in this SO post here.

    The trick is to override shouldPerformSegueWithIdentifier in VC3. Inside it, you can place your condition check and return false in case the segue should be stopped. Otherwise, return true to make the segue happen. Here is a sample code for your case.

    override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
    
        if identifier == "submitUnwindSegue"{
            if string.toInt() < minimum {
                //fire an alert controller about the error
                return false
            }
        }
    
        //Continue with the segue
        return true