How to configure a WKWebView to fill an NSWindow?
<p>I have a small prototype application developed in Swift with XCode 7.2.  The application was created as a Cocoa document-based application with a storyboard. As such, the project contains <code>AppDelegate.swift</code>, <code>Document.swift</code> and <code>Main.storyboard</code>, all of which are unchanged from what XCode generated, and <code>ViewController.swift</code>, which contains this:</p>

<pre><code>import Cocoa
import WebKit

class ViewController: NSViewController {

    var webView: WKWebView {
        return view as! WKWebView
    }

    override func loadView() {
        view = WKWebView(/*frame: CGRect(x: 0, y: 0, width: 200, height: 200)*/)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        webView.loadHTMLString("&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello, World!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;", baseURL: nil)
    }
}
</code></pre>

<p>I have overridden <code>loadView()</code> to directly create the a <code>WKWebView</code> and assign it to the <code>view</code> property of <code>ViewController</code> as the root view, rather than loading the view defined in the storyboard.</p>

<p>Notice that the <code>frame</code> argument to <code>WKWebView</code> may be commented in or out to demonstrate the different behaviours which are at the root of this question.</p>

<h1>Desired behaviour</h1>

<p>A <code>WKWebView</code> instance should fill the window corresponding to each document, and the initial size and position of new document windows should be those defined for the <code>NSWindow</code> in the storyboard (480x270 at (196, 240)).  The <code>WKWebView</code> should resize with the enclosing window.</p>

<h1>Observed behaviour</h1>

<h2>Without the <code>frame</code> argument</h2>

<p><em>Without</em> the <code>frame</code> argument, no document window is displayed when running the application, even though the Window menu shows that an 'Untitled' document has been created. Neither are document windows displayed when further documents (Untitled 2, etc) are created with <em>File > New</em>.</p>

<p>However, if a document is shown full-screen using the <em>View > Enter Full Screen</em>, the <code>WKWebView</code> and its greeting are displayed as expected.</p>

<h2>With the <code>frame</code> argument</h2>

<p><em>With</em> the <code>frame</code> argument, document windows containing the <code>WKWebView</code> and its greeting are displayed at the size and position given in the <code>CGRect</code>.</p>

<h1>Question</h1>

<p>I don't understand why, when the frame of the <code>WKWebView</code> is not specified, the view is forced to the size of the container (the screen) in full-screen mode, but in windowed mode the opposite seemingly happens: The window is  forced to the (degenerate?) size of the view, and so becomes invisible.  I was expecting new views to adopt the size of the window as defined in the storyboard.</p>

<p>In my <code>ViewController</code>, how do I configure my <code>WKWebView</code> instances to fill the <code>NSWindow</code> the document framework produces corresponding to each <code>NSDocument</code>?   Or, perhaps my approach is wrong-headed, and I should embrace configuring the initial window size via the view size in <code>ViewController.loadView()</code>?</p>