title: Swift NSObject class does not reliably respond to delegate method calls
body: <p>I have had a couple of instances of this recently, so I thought I'd reach out to better understand if I am doing something wrong or iOS/Xcode is just being weird.</p>
  
  <p>I have a utility class, which just inherits from NSObject. My utility class holds reference to a WKWebView, and is the webview's navigationDelegate.</p>
  
  <p>For the life of me, I cannot get the utility class to respond to the navigationDelegate methods, UNLESS I breakpoint at the point of setting the delegate, print out something (anything, from my testing) to the console (yep, this is important. Just breakpointing isn't enough - I have to PRINT something). Then re-run, and it responds as normal.</p>
  
  <p>I am very familiar with iOS development and delegation patterns, but this is behaviour I've seen before and never understood, so I wanted to better my understanding if it's something I am getting wrong.</p>
  
  <p>Here is some example code of what I am doing. It's worth noting, that if I take the utility out of the equation and just use UIViewControllers as the navigationDelegate, everything works fine.</p>
  
  <pre><code>class ExampleUtility: NSObject, WKNavigationDelegate {
  private weak var containerViewController: UIViewController?
  private let webView: WKWebView
  
  init(containerViewController: UIViewController) {
      self.containerViewController = containerViewController
      webView = WKWebView(frame: containerViewController.view.frame)
      super.init()
      setupWebView()
  }
  
  private func setupWebView() {
      webView.navigationDelegate = self
      containerViewController?.view.addSubview(webView)
  }
  
  func start() {
      guard let url = URL(string: urlString) else {
          return
      }
      let request = URLRequest(url: url)
      webview.load(request)
  }
  
  public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
      // This is never called, unless I print ANYTHING to the console 
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The fact that it responds after breakpointing and printing makes me thing its a bug of some sort? Also worth nothing that this isn't only on debug runs. It happens when not running from Xcode also.</p>
  
  <p>Any help is greatly appreciated.</p>