Question: Suppose I have a nav controller stack with 2 view controllers: VC2 is on top and VC1 is underneath. Is there code I can include in VC1 that will detect that VC2 has just been popped off the stack? 

Since I'm trying to detect the popping of VC2 from within the code for VC1 it seems that something like **viewWillAppear** or **viewDidAppear** won't work, because those methods fire every time VC1 is displayed, including when it is first pushed on the stack.

**EDIT:** it seems I was not very clear with my original question. Here's what I'm trying to do: determine when VC1 is being shown due to VC2 being popped off the top of the stack. Here's what I'm NOT trying to do: determine when VC1 is being shown due to being pushed onto the top of the stack. I need some way that will detect the first action but NOT the second action. 

Note: I don't particularly care about VC2, it can be any number of other VCs that get popped off the stack, what I do care about is when VC1 becomes the top of the stack again due to some other VC begin popped off the top.

Answer: 
I got the same situation but with slight more specific use case. In my case 
we wanted to determine if a VC1 is appeared/displayed when user tap on VC2's back button where VC2 is pushed on navigationController over VC1.

So I used help of [snarshad's answer](https://stackoverflow.com/a/26308475/596360) to customised as per my need. Here is the code in VC1's `viewDidAppear` in **swift 3**.

```
// VC1: ParentViewController
// VC2: ChildViewController

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        if let transitionCoordinator = navigationController?.transitionCoordinator,
            let fromVC = transitionCoordinator.viewController(forKey: UITransitionContextViewControllerKey.from),
            let toVC = transitionCoordinator.viewController(forKey: UITransitionContextViewControllerKey.to),
            fromVC is ChildViewController,
            toVC is ParentViewController {

            print("Back button pressed on ChildViewController, and as a result ParentViewController appeared")
        }
    }

```
Yes, in **VC1** you can check whether **VC2** is popped or not. UINavigationController there is one method **viewControllers** which will returns the array of pushed **Controllers**, which are in the stack (i.e. which have been pushed).

So you iterate through loop by comparing class. If **VC2** is there, will have match, otherwise not.