WKWebView open links from certain domain in safari
<p>Within my app I am want to open links from within <em>my</em> domain (e.g.: communionchapelefca.org) in WKWebView but then have links from <em>other</em> domains open in Safari. I would prefer to do this programmatically.</p>
<p>I have found a few solutions on Stack overflow (<a href="https://stackoverflow.com/questions/5899990/objective-c-open-links-from-uiwebview-in-safari">here</a>, <a href="https://stackoverflow.com/questions/3594136/uiwebview-open-certain-links-in-safari-not-all">here</a>, <a href="https://stackoverflow.com/questions/15537289/open-webview-links-in-safari">here</a>, and <a href="https://stackoverflow.com/questions/27464407/limit-uiwebview-to-specific-url-swift">here</a>) but they all seem to be Obj-C based and I am looking for a solution using Swift.</p>
<p>ViewController.swift:</p>
<pre><code>import UIKit
import WebKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myWebView:WKWebView = WKWebView(frame: CGRectMake(0, 0,   UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
        
        myWebView.loadRequest(NSURLRequest(URL: NSURL(string: &quot;http://www.communionchapelefca.org/app-home&quot;)!))
        
        self.view.addSubview(myWebView)
</code></pre>