Search code examples
iosxcodewkwebviewnscoding

Xcode 9 GM - WKWebView NSCoding support was broken in previous versions


Does anyone know how to fix this error with Xcode 9 GM? I'm working on an app made with Xcode 8.3, the deployment target is for iOS 9.3 and I never had this problem before. I don't find any information here or on Apple forums yet :(

Edit: This error came when I put a WKWebView into interface builder, not if I use it programmatically.

See picture WKWebView Error

Edit 2: Well, it's finally not a bug, see Quinn's answer below to have more information about this behavior. Thanks to him for the explanation.


Solution

  • The error is correct behavior, and not a bug in Xcode 9. Although WKWebView was introduced in iOS 8, there was a bug in -[WKWebView initWithCoder:] that was only fixed in iOS 11, which always crashed at runtime and thus prevented configuring one within Interface Builder.

    https://bugs.webkit.org/show_bug.cgi?id=137160

    Rather than allow developers to build something in IB that would be broken at runtime, it is a build error. It's an inconvenient limitation since iOS 11 was only recently released, but there's really no other good option.

    The workaround for older deployment targets is to continue to add the WKWebView in code, as @fahad-ashraf already described in his answer:

    https://developer.apple.com/documentation/webkit/wkwebview