title: Why is my value only being set after the app is opened and closed for the first time in swift?
body: <p>I have a value, showAds, that determines wether or not the user has purchased noAds or not. If it is true then ads are displayed. It works for the most part, except for when the user opens the app for the first time it does not show ads. If they close out the app and open it again, then ads show as they should. How do I fix this? Thank you, any help is appreciated!</p>
  
  <p>Here is all of the code associated with that value:</p>
  
  <pre><code>var showAds = UserDefaults.standard.bool(forKey: "showAds")
  
  
  
  func adViewDidReceiveAd(_ bannerView: GADBannerView) {
      if showAds == true {
  
          view.addSubview(bannerView)
  
      }
  }
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  
      UserDefaults.standard.set(true, forKey: "showAds")
  
      let userDefaults = UserDefaults.standard
      let appDefaults = ["showAds" : true]
      userDefaults.register(defaults: appDefaults)
       print("SHOWING ADS: \(showAds)")
  
      if showAds == true {
  
          self.view?.addSubview(bannerView)
  
      }
  
      if showAds == false {
  
  
          bannerView.removeFromSuperview()
  
      }
  
  }
  </code></pre>