Swift: popToRootViewController with animation bug

Recently, when I was working on my project, I would like to get the current displayed viewController by observing the navigationController delegate:

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
print("Will show: \(viewController)")
}

Then, I noticed it was not the expected top viewController after calling popToRootViewController(animated: true).

There are steps to reproduce:

  1. Create a new Xcode project and create viewControllers A,B,C(more than two viewControllers)
  2. Push A to B to C
  3. In ViewController C, trigger a button to pop to root viewController which function named "navigationController?.popToRootViewController(animated: true)"

Before step 3, the navigation stack is like [A, B, C], but After step 3 , the navigation stack is like [C, A] not as expected result that just remain the top viewController [A]. But if I disable the pop animation as "false", it would be only top viewController [A].

I think it's mostly like an Apple internal bug?

Swift: popToRootViewController with animation bug
 
 
Q