WebKit View in projects compiled in 10.2.1 failing

I've just tried moving from Xcode 10.1 to Xcode 10.2.1. Now projects that include a WebView Kit UI element are behaving oddly. So I decided to start simple:


1: Create new Xcode Project > macOS > Cocoa App

2: Choose Language Swift and Use Storyboards is checked

3: On the Main.storyboard, drag and drop a WebKit View to the main view controller - nothing else added to the controller - no code written

4: Add:


import WebKit



to ViewController.swift

5: Run the app via Build and Run


The app will compile and launch. However, it appears to never finish initialization. Attempts to use Command Q will not quit the app, however, going to the app menu and choose quit will quit the app. Nothing appears in the debug area.


Ah, but, now right click on the .app in the Products folder and choose Show in Finder. Opening the app from there will immediate crash the app.


If I repeat the steps above, but connect the WebKit View to my ViewController.swift, then I get a blank window when run from the Finder (the WebKit UI does not appear). For example:


1: Create new Xcode Project > macOS > Cocoa App

2: Choose Language Swift and Use Storyboards is checked

3: On the Main.storyboard, drag and drop a WebKit View to the main view controller - nothing else added to the controller - no code written

4: Add:


import WebKit


to ViewController.swift

5: Connect WebKit View to my ViewController.swift creating


@IBOutlet waek var myWebView: WKWebView!


6: Run the app via Build and Run


In this case, doing a Build and Run will show the expected interface but Command Q still will not quit the app. But then it gets odder. If I run the app from the Finder, I get a blank Window with NO UI elements. So creating the outlet prevents the crash on launch, but then my UI is no longer visible. Meanwhile, Command Q will quit the app when run from the Finder!?!


I am confused by this change.


So I am rolling back to 10.1 as the same project will run as expected in both the debugger and when launched from the Finder. Likewise, if I perform the procedures above on a machine with Xcode 10.1, I get the expected results. The app will run in the debugger, accept the Command Q to quit, and run when launching from the Finder. My custom UI appears in all cases.


Have I missed something in 10.2.1 regarding how to place and use a WebKit View? Any help would be appreciated. I've never experienced an issue like this as I tend to create the interface first before hooking up code. Now UI prototyping appears to be impossible when a WebKit View is involved.


Thanks for looking.

Replies

@IBOutlet waek var myWebView: WKWebView! 


What is waek?

I have exactly the same thing. I can run the app with build button. But as soon as I open the app (in build folder), the app crash immediately. I have quiet big project and it makes me pull out my hair to locate this issue with webview, because i don't have any warning or error, so i have do split controller to controller until I can tell there is a problem with webview. I hope someone knows how to fix this issue

I just figure out that if we go to General -> Select target -> Add WebKit to Linked Frameworks and Libraries, then the app will not crash any more