Skip to content

Commit 3728637

Browse files
committed
improve demo code
1 parent f9f87f5 commit 3728637

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

WKWebViewJavascriptBridgeDemo/ViewController.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ViewController: UIViewController {
4040
bridge = WKWebViewJavascriptBridge(webView: webView)
4141
bridge.register(handlerName: "testiOSCallback") { (paramters, callback) in
4242
print("testiOSCallback called: \(String(describing: paramters))")
43-
callback!("Response from testiOSCallback")
43+
callback?("Response from testiOSCallback")
4444
}
4545
bridge.call(handlerName: "testJavascriptHandler", data: ["foo": "before ready"], callback: nil)
4646
}
@@ -56,12 +56,11 @@ class ViewController: UIViewController {
5656
}
5757

5858
do {
59-
let pagePath = Bundle.main.path(forResource: "Demo", ofType: "html")
60-
guard pagePath != nil else {
59+
guard let pagePath = Bundle.main.path(forResource: "Demo", ofType: "html") else {
6160
throw LoadDemoPageError.nilPath
6261
}
63-
let pageHtml = try String(contentsOfFile: pagePath!, encoding: .utf8)
64-
let baseURL = URL(fileURLWithPath: pagePath!)
62+
let pageHtml = try String(contentsOfFile: pagePath, encoding: .utf8)
63+
let baseURL = URL(fileURLWithPath: pagePath)
6564
webView.loadHTMLString(pageHtml, baseURL: baseURL)
6665
} catch LoadDemoPageError.nilPath {
6766
print(print("webView loadDemoPage error: pagePath is nil"))

0 commit comments

Comments
 (0)