@@ -17,114 +17,113 @@ class WebViewController: UIViewController, UISearchBarDelegate, WKNavigationDele
1717
1818 override func viewDidLoad( ) {
1919 super. viewDidLoad ( )
20- self . onepasswordFillButton. hidden = ( false == OnePasswordExtension . sharedExtension ( ) . isAppExtensionAvailable ( ) )
20+ self . onepasswordFillButton. isHidden = ( false == OnePasswordExtension . shared ( ) . isAppExtensionAvailable ( ) )
2121
2222 let configuration = WKWebViewConfiguration ( )
2323
2424 self . webView = WKWebView ( frame: self . webViewContainer. bounds, configuration: configuration)
25- self . webView. autoresizingMask = UIViewAutoresizing ( arrayLiteral: . FlexibleHeight , . FlexibleWidth )
25+ self . webView. autoresizingMask = UIViewAutoresizing ( arrayLiteral: . flexibleHeight , . flexibleWidth )
2626 self . webView. navigationDelegate = self
2727 self . webViewContainer. addSubview ( self . webView)
2828
29- let htmlFilePath = NSBundle . mainBundle ( ) . pathForResource ( " welcome " , ofType: " html " )
29+ let htmlFilePath = Bundle . main . path ( forResource : " welcome " , ofType: " html " )
3030 var htmlString : String !
3131 do {
32- htmlString = try String ( contentsOfFile: htmlFilePath!, encoding: NSUTF8StringEncoding )
32+ htmlString = try String ( contentsOfFile: htmlFilePath!, encoding: String . Encoding . utf8 )
3333 }
3434 catch {
35- print ( " Failed to obtain the html string from file \( htmlFilePath) with error: < \( error) > " )
35+ print ( " Failed to obtain the html string from file \( String ( describing : htmlFilePath) ) with error: < \( String ( describing : error) ) > " )
3636 }
3737
38- self . webView. loadHTMLString ( htmlString, baseURL: NSURL ( string: " https://agilebits.com " ) )
38+ self . webView. loadHTMLString ( htmlString, baseURL: URL ( string: " https://agilebits.com " ) )
3939 }
4040
41- @IBAction func fillUsing1Password( sender: AnyObject ) -> Void {
42- OnePasswordExtension . sharedExtension ( ) . fillItemIntoWebView ( self . webView, forViewController : self , sender: sender, showOnlyLogins: false ) { ( success, error) -> Void in
41+ @IBAction func fillUsing1Password( _ sender: AnyObject ) -> Void {
42+ OnePasswordExtension . shared ( ) . fillItem ( intoWebView : self . webView, for : self , sender: sender, showOnlyLogins: false ) { ( success, error) -> Void in
4343 if success == false {
44- print ( " Failed to fill into webview: < \( error) > " )
44+ print ( " Failed to fill into webview: < \( String ( describing : error) ) > " )
4545 }
4646 }
4747 }
4848
49- @IBAction func goBack( sender: AnyObject ) -> Void {
49+ @IBAction func goBack( _ sender: AnyObject ) -> Void {
5050 let navigation = self . webView. goBack ( )
5151
5252 if navigation == nil {
53- let htmlFilePath = NSBundle . mainBundle ( ) . pathForResource ( " welcome " , ofType: " html " )
53+ let htmlFilePath = Bundle . main . path ( forResource : " welcome " , ofType: " html " )
5454 var htmlString : String !
5555 do {
56- htmlString = try String ( contentsOfFile: htmlFilePath!, encoding: NSUTF8StringEncoding )
56+ htmlString = try String ( contentsOfFile: htmlFilePath!, encoding: String . Encoding . utf8 )
5757 }
5858 catch {
59- print ( " Failed to obtain the html string from file \( htmlFilePath) with error: < \( error) > " )
59+ print ( " Failed to obtain the html string from file \( String ( describing : htmlFilePath) ) with error: < \( String ( describing : error) ) > " )
6060 }
6161
62- self . webView. loadHTMLString ( htmlString, baseURL: NSURL ( string: " https://agilebits.com " ) )
62+ self . webView. loadHTMLString ( htmlString, baseURL: URL ( string: " https://agilebits.com " ) )
6363 }
6464 }
65- @IBAction func goForward( sender: AnyObject ) -> Void {
65+ @IBAction func goForward( _ sender: AnyObject ) -> Void {
6666 self . webView. goForward ( )
6767 }
6868
6969 // UISearchBarDelegate
7070 func searchBarSearchButtonClicked( searchBar: UISearchBar ) {
71- self . performSearch ( searchBar. text)
71+ self . performSearch ( text : searchBar. text)
7272 }
7373
7474 func searchBarTextDidEndEditing( searchBar: UISearchBar ) {
75- self . performSearch ( searchBar. text)
75+ self . performSearch ( text : searchBar. text)
7676 }
7777
7878 func handleSearch( searchBar: UISearchBar ) {
79- self . performSearch ( searchBar. text)
79+ self . performSearch ( text : searchBar. text)
8080 }
8181
8282 func searchBarCancelButtonClicked( searchBar: UISearchBar ) {
83- self . performSearch ( searchBar. text)
83+ self . performSearch ( text : searchBar. text)
8484 }
8585
8686 // Convenience
8787 func performSearch( text: String ! ) {
88- let lowercaseText = text. lowercaseStringWithLocale ( NSLocale . currentLocale ( ) )
89- var URL : NSURL ?
88+ let lowercaseText = text. lowercased ( with : NSLocale . current )
89+ var url : URL ?
9090
91- let hasSpaces = lowercaseText. rangeOfString ( " " ) != nil
92- let hasDots = lowercaseText. rangeOfString ( " . " ) != nil
91+ let hasSpaces = lowercaseText. range ( of : " " ) != nil
92+ let hasDots = lowercaseText. range ( of : " . " ) != nil
9393
9494 let search : Bool = !hasSpaces || !hasDots
9595 if ( search) {
9696 let hasScheme = lowercaseText. hasPrefix ( " http: " ) || lowercaseText. hasPrefix ( " https: " )
9797 if ( hasScheme) {
98- URL = NSURL ( string: lowercaseText)
98+ url = URL ( string: lowercaseText)
9999 }
100100 else {
101- URL = NSURL ( string: " https:// " . stringByAppendingString ( lowercaseText) )
101+ url = URL ( string: " https:// " + lowercaseText)
102102 }
103103 }
104104
105- if ( URL == nil ) {
106- let URLComponents = NSURLComponents ( )
107- URLComponents . scheme = " https "
108- URLComponents . host = " www.google.com "
109- URLComponents . path = " /search "
105+ if ( url == nil ) {
106+ let urlComponents = NSURLComponents ( )
107+ urlComponents . scheme = " https "
108+ urlComponents . host = " www.google.com "
109+ urlComponents . path = " /search "
110110
111- let queryItem = NSURLQueryItem ( name: " q " , value: text)
112- URLComponents . queryItems = [ queryItem]
111+ let queryItem = URLQueryItem ( name: " q " , value: text)
112+ urlComponents . queryItems = [ queryItem]
113113
114- URL = URLComponents . URL
114+ url = urlComponents . url
115115 }
116116
117- self . searchBar. text = URL ? . absoluteString
117+ self . searchBar. text = url ? . absoluteString
118118 self . searchBar. resignFirstResponder ( )
119119
120- let request = NSURLRequest ( URL : URL !)
121- self . webView. loadRequest ( request)
120+ let request = URLRequest ( url : url !)
121+ self . webView. load ( request)
122122 }
123123
124124 // WKNavigationDelegate
125-
126- func webView( webView: WKWebView , didFinishNavigation navigation: WKNavigation ! ) {
127- self . searchBar. text = webView. URL? . absoluteString
125+ func webView( _ webView: WKWebView , didFinish navigation: WKNavigation ! ) {
126+ self . searchBar. text = webView. url? . absoluteString
128127
129128 if self . searchBar. text == " about:blank " {
130129 self . searchBar. text = " "
0 commit comments