title: Why is XCode giving me an 'unrecognized selector' error?
body: <p>I'm developing a Mac app using Swift 2 and Xcode 7.</p>
  
  <p>I'm just getting started with Swift after many years focused on Ruby with a touch of JavaScript.</p>
  
  <p>The Mac app that I'm creating includes a web browser view.</p>
  
  <p>My <code>ViewController.swift</code> says:</p>
  
  <pre><code>import Cocoa
  import WebKit
  
  class ViewController: NSViewController {
  
      @IBOutlet var url: NSTextField!
      @IBOutlet var browser: WKWebView!
  
      @IBAction func go(sender: AnyObject) {
  
          // browser.loadRequest(NSURLRequest(URL:NSURL(string: url.stringValue)!))
          // above line broken down for debugging
  
          let url1 = url.stringValue
          print("url1 = \(url1)")
  
          let url2 = NSURL(string: url1)!
          print("url2 = \(url2)")
  
          let url3 = NSURLRequest(URL:url2)
          print("url3 = \(url3)")
  
          print("browser is \(browser)")
  
          browser.loadRequest(url3)
  
      }
  }
  </code></pre>
  
  <p>The app builds successfully. When I run it, enter <code>http://apple.com</code> into the URL  field and click the Go button, I see:</p>
  
  <pre><code>url1 = http://apple.com
  url2 = http://apple.com
  url3 = &lt;NSURLRequest: 0x600000001400&gt; { URL: http://apple.com }
  browser is &lt;WebView: 0x608000120e60&gt;
  2016-04-06 13:39:51.664 Testivate[6516:427535] -[WebView loadRequest:]: unrecognized selector sent to instance 0x608000120e60
  2016-04-06 13:39:51.664 Testivate[6516:427535] -[WebView loadRequest:]: unrecognized selector sent to instance 0x608000120e60
  2016-04-06 13:39:51.667 Testivate[6516:427535] (
      0   CoreFoundation                      0x00007fff93f4a4f2 __exceptionPreprocess + 178
      1   libobjc.A.dylib                     0x00007fff8ca7a73c objc_exception_throw + 48
      2   CoreFoundation                      0x00007fff93fb41ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
      3   CoreFoundation                      0x00007fff93eba571 ___forwarding___ + 1009
      4   CoreFoundation                      0x00007fff93eba0f8 _CF_forwarding_prep_0 + 120
      5   Testivate                           0x000000010000271a _TFC9Testivate14ViewController2gofPs9AnyObject_T_ + 2154
      6   Testivate                           0x00000001000027b6 _TToFC9Testivate14ViewController2gofPs9AnyObject_T_ + 54
      7   libsystem_trace.dylib               0x00007fff96e1807a _os_activity_initiate + 75
      8   AppKit                              0x00007fff94567e89 -[NSApplication sendAction:to:from:] + 460
      9   AppKit                              0x00007fff94579fde -[NSControl sendAction:to:] + 86
      10  AppKit                              0x00007fff94579f08 __26-[NSCell _sendActionFrom:]_block_invoke + 131
      11  libsystem_trace.dylib               0x00007fff96e1807a _os_activity_initiate + 75
      12  AppKit                              0x00007fff94579e65 -[NSCell _sendActionFrom:] + 144
      13  libsystem_trace.dylib               0x00007fff96e1807a _os_activity_initiate + 75
      14  AppKit                              0x00007fff9457848a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
      15  AppKit                              0x00007fff945c0fd0 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
      16  AppKit                              0x00007fff94576bb4 -[NSControl mouseDown:] + 669
      17  AppKit                              0x00007fff94acb469 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
      18  AppKit                              0x00007fff94acc44d -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
      19  AppKit                              0x00007fff9450b63d -[NSWindow sendEvent:] + 517
      20  AppKit                              0x00007fff9448bb3c -[NSApplication sendEvent:] + 2540
      21  AppKit                              0x00007fff942f2ef6 -[NSApplication run] + 796
      22  AppKit                              0x00007fff942bc46c NSApplicationMain + 1176
      23  Testivate                           0x0000000100004f34 main + 84
      24  libdyld.dylib                       0x00007fff9099a5ad start + 1
      25  ???                                 0x0000000000000003 0x0 + 3
  )
  </code></pre>
  
  <p>Initially I thought the error was saying that <code>loadRequest</code> was an unrecognized selector for <code>browser</code>, but you can see I've pulled apart the function and <code>browser</code> is clearly an instance of <code>WebView</code>, which <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/" rel="nofollow noreferrer">definitely has <code>loadRequest</code> as a method</a>. You can see from how I've pulled apart the method that I'm definitely providing the <code>loadRequest</code> method with the expected <code>NSURLRequest object</code>.</p>
  
  <p>I'm now thinking that maybe this has something to do with being unable to find the WebView in <code>Main.storyboard</code>, but surely it should be able to? I've defined connections on it like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Yfslc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yfslc.png" alt="Screenshot of Connections Inspector"></a></p>
  
  <p>When you view <code>Main.storyboard</code> as source, it says:</p>
  
  <pre><code>&lt;webView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ocj-mD-woP"&gt;
      &lt;rect key="frame" x="62" y="20" width="406" height="211"/&gt;
      &lt;webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12"&gt;
          &lt;nil key="identifier"/&gt;
      &lt;/webPreferences&gt;
  &lt;/webView&gt;
  </code></pre>
  
  <p>Any thoughts? Thanks.</p>