How to Resolve “Couldn’t instantiate class named WKWebView” Error When Using WebKit

I got a question from a reader about the following error when using WKWebView in storyboard:

Could not instantiate class named WKWebView because no class named WKWebView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)’

He created a view controller with a WKWebView using Interface Builder (or storyboard) and connected it with code via an outlet variable like this:

When accessing the web view, the app quit and showed the error above.

To resolve the error, all you need is add the WebKit framework to your Xcode project. In case you don’t know to how manually add the framework, follow these procedures:

1. In the project navigator, select your project.

2. Next, select the target and choose the Build Phase tab.

Xcode Project Using WKWebView

3. Under the Link Binary with Libraries section, click the + button.

4. Key in WebKit and then add the WebKit framework.

Adding the WebKit framework

That’s it. Run your project again and you should be able to launch the web view without the error.

Using SwiftData with Preview in SwiftUI
The Complete Guide to PHPicker API in iOS 14
Working with the new NavigationStack in SwiftUI