Modally view back to previous screen

Hello CodeCrew,

I’m working on an app which is able to scan a barcode, the scanning part is done in a modally view which I call from a button on the first view.

When the scanning is complete it should get the barcode back to the first view from where the modally view was started.

When I make a segue from the modally view back to the first view and give it an identifier it opens this first view in modally mode on top of the barcode scanning modally view.

How can I avoid this behavior so it just dismisses itself and return the barcode in a textLabel?

This is the code of the scannerView which is presented modally

if barcodeData != nil {
            self.performSegue(withIdentifier: "returnBarcodeSegue", sender: self)

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "returnBarcodeSegue", let viewController = segue.destination as? SearchViewController {
        viewController.barcodeData = self.barcodeData

Look into unwind segues