title: Swift 3.0 Adding a Right Button to Navigation Bar
body: <p>I have added a navigation bar to the top of a view controller. I am trying to control whether a button is visible based a condition, but I am having trouble adding the button. So far I have,</p>
  
  <pre><code>var addButton: UIBarButtonItem = UIBarButtonItem(title: "test", style: .done, target: self, action: #selector(addTapped))
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let boool = true
      if boool {
          self.navigationItem.rightBarButtonItem = self.addButton
      }
      else {
          self.navigationItem.rightBarButtonItem = nil
      }
  }
  
  func addTapped(sender: AnyObject) {
      print("hjxdbsdhjbv")
  }
  </code></pre>
  
  <p>I believe it is not working properly because I have added a navigation bar into the VC, instead of using a navigation controller and working with the bar there. I was wondering if there was a way to work with this navigation bar. </p>