Search code examples
iosswiftuiviewibeacon

stop performseguewithidentifier once executed


I have this code to update distance using beacons.

func updateDistance(distance: CLProximity) {
    UIView.animateWithDuration(0.8) {
        switch distance {
        case .Unknown:
            print("unknown")
        case .Far:
            print("far")
        case .Near:
            print("near")
        case .Immediate:
             print("Immediate")
             self.performSegueWithIdentifier("beaconSegue", sender: self)
        }
    }
}

I would just like to ask if how to stop the self.performSegueWithIdentifier function once its already executed.


Solution

  • Just set a flag when you first perform the segue. Like this:

    var seguePerformed = false
    
    func updateDistance(distance: CLProximity) {
        UIView.animateWithDuration(0.8) {
            switch distance {
            case .Unknown:
                print("unknown")
            case .Far:
                print("far")
            case .Near:
                print("near")
            case .Immediate:
                 print("Immediate")
                 if !self.seguePerformed {
                     self.seguePerformed = true
                     self.performSegueWithIdentifier("beaconSegue", sender: self)
                 }
            }
        }
    }