I would like to suggest another approach to this problem. Instead of using the navigation controller to pop a view controller, use unwind segues. This solution has a few, but really important, advantages:
- The origin controller can go back to any other destination controller (not just the previous one) without knowing anything about the destination.
- Push and pop segues are defined in storyboard, so no navigation code in your view controllers.
You can find more details in Unwind Segues Step-by-Step. The how to is better explained in the former link, including how to send data back, but here I will make a brief explanation.
1) Go to the destination (not the origin) view controller and add an unwind segue:
@IBAction func unwindToContact(_ unwindSegue: UIStoryboardSegue) {
//let sourceViewController = unwindSegue.source
// Use data from the view controller which initiated the unwind segue
}
2) CTRL drag from the view controller itself to the exit icon in the origin view controller:

3) Select the unwind function you just created a few moments ago:

4) Select the unwind segue and give it a name:

5) Go to any place of the origin view controller and call the unwind segue:
performSegue(withIdentifier: "unwindToContact", sender: self)
I have found this approach payoffs a lot when your navigation starts to get complicated.
I hope this helps someone.