Q:

Swift EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) with WebView

I try to make simple OSX application with WebView. I am new in Swift, and have some errors:
it's my WebView delegate file:
class WebViewControllerDelegate: NSObject{

@IBOutlet var webview: WebView!

override init()
{
    super.init()
    self.webview.frameLoadDelegate = self
    let url = NSURL(string: "http://google.com")
    let request = NSURLRequest(URL: url);
    self.webview.mainFrame.loadRequest(request)
}

func didFinishLoadForFrame()
{
    println("ok:")
}

}
I try to run this, but have EXC_BAD_INSTRUCTION error at line where I set frameLoadDelegate to self. I think it's error with web view outlet, but i can't fix it.
self.webview is nil, and i don't know why...

A:

Views in Xib / Storyboard files are not loaded nor connected during initialization. That is why self.webview is nil in your code.
You really should not attach the IBOutlet directly to your "delegate". Instead, connect it to your view controller and have the view controller set it on the delegate. You should do that in viewDidLoad because that is when you can guarantee all of the objects have been created and connected.

