Delegate is getting reset to nil

I have a NewCartViewController that’s embedded in a UINavigationController

In my ContainerViewController:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "goToCart" {
        self.cartVC = segue.destination as? NewCartViewController
        self.cartVC?.delegate = self

        print("cartVC Delegate", cartVC?.delegate) // value is NOT nil here

        let pendingCart = PendingCart(color: .blue)

        self.cartVC?.setupPaintOrder(cart: pendingCart)
    }
}

In my NewCartViewController

protocol NewCartViewControllerDelegate: class {
    func vcDidFinishWithCancel(_ newCartViewController: NewCartViewController)
}

class NewCartViewController: UIViewController {

    weak var delegate: NewCartViewControllerDelegate?

    ....

    @objc func dismissVC() { // called from the leftBarButtonItem
        print(delegate) // nil
    }

I’ve looked at other answers that are related but I’m not sure what’s going on here. Any help would be appreciated. Thanks!

Edit – more detail on how the VC is instantiated:

My BuyButtonVC calls a delegate method back to AddToCartContainerVC:

extension AddToCartContainerViewController: BuyButtonViewControllerDelegate {
    func buyButtonVCDidPressButton(_ vc: BuyButtonViewController) {
         performSegue(withIdentifier: "goToCart", sender: self)
    }
}

Which then fires the prepare(for segue:) function from the first code block above where the we look at the the segue.destination and set the delegate.

I have a print on the didSet on the delegate in my NewCartViewController and I see that the delegate is set.

The user goes to the screen, the didSet is never called again as if it was getting set to nil. But then when I try to call the delegate method in the second code block, the delegate is nil

Source: Ios