Removing right bar button item from navigation item

Swift 5/4/3 - I have a couple of buttons on both left and right side of navigation bar so I hide them using:

func hideNavItems() {
  navigationItem.setLeftBarButtonItems(nil, animated: true)
  navigationItem.setRightBarButtonItems(nil, animated: true)
}

In my case I actually need to show those buttons again at later point so I keep them in an array:

var leftNavItems: [UIBarButtonItem]!
var rightNavItems: [UIBarButtonItem]!

and then I just call a function to show (re-add) them:

func showNavItems() {
  navigationItem.setLeftBarButtonItems(leftNavItems, animated: true)
  navigationItem.setRightBarButtonItems(rightNavItems, animated: true)
}

What you're doing should work. I've done that lots of times. Are you sure you're removing the button from the correct navigation item? Is self the currently displayed UIViewController?