You can use the Exit (i.e. unwind your segue) provided.
In your first view controller you need to add an IBAction function, with a UIStoryboardSegue as a parameter. Here we'll call it @IBAction func unwindFromSecondVC(segue: UIStoryboardSegue)
. Inside which you'll be able to access the view controller you're coming back from.
In your second view controller you can perform the action you have to do.
In the view itself (storyboard), you just place a button in order to go back when you'll need. Link this button to the Exit of the view controller (orange square on top of it, see capture at bottom). This could also be done programmatically if you don't need a button.
ViewController.swift :
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Here, you pass your parameter(s) to the secondVC.
}
@IBAction func unwindFromSecondVC(segue: UIStoryboardSegue) {
// Here you can receive the parameter(s) from secondVC
let secondVC : SecondViewController = segue.sourceViewController as SecondViewController
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
SecondViewController.swift
import UIKit
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// You can do stuff here (but to go forward not backward in segue).
// But in your case, see firstVC.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Storyboard :
Example from another Q/A : http://goo.gl/J35mC6
