Is it possible to add WKWebViewConfiguration() manually to my WKWebView without instantiation? I ask this because I have an IBOutlet WKWebView from Storyboard(with constrains).
This works (not from Storyboard - manually instantiate):
var myWebView: WKWebView!
let webConfiguration = WKWebViewConfiguration()
myWebView = WKWebView(frame: view.bounds, configuration: webConfiguration)
What I want to do is something like this:
@IBOutlet weak var myWebView: WKWebView!
let webConfiguration = WKWebViewConfiguration()
myWebView.configuration = webConfiguration //this line does not work
All other stuff is working with an IBOutlet WKWebView, just the configuration are not passing through for JS Bridge e.g.
Someone an idea how to allocate the WKWebViewConfiguration() to my IBOutlet WKWebView?
myWebView.configuration = webConfiguration //this line does not work
Indeed. The
configuration
property is read-only; the only way to set it is when you construct the web view via its
init(frame:configuration:)
initialiser, and you can’t do that when you instantiate the web view from a nib or storyboard. If you absolutely have to set the configuration, to configure web-to-native messaging for example, you must construct the web view programmatically.
Fortunately that’s pretty easy. You typically have a custom view controller running the web view anyway, so you can set it in your
loadView()
implementation.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"