Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 5fae731

Browse files
author
Kyle Swank
committed
Update ACME Browser for iOS Swift project for Swift 4
1 parent 4807e9b commit 5fae731

File tree

3 files changed

+64
-48
lines changed

3 files changed

+64
-48
lines changed

Demos/WebView Demo for iOS Swift/WebView Demo for iOS Swift.xcodeproj/project.pbxproj

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
isa = PBXProject;
111111
attributes = {
112112
LastSwiftUpdateCheck = 0700;
113-
LastUpgradeCheck = 0710;
113+
LastUpgradeCheck = 0910;
114114
ORGANIZATIONNAME = "AgileBits Inc.";
115115
TargetAttributes = {
116116
C0525F661B05831F003613F5 = {
@@ -183,13 +183,21 @@
183183
CLANG_CXX_LIBRARY = "libc++";
184184
CLANG_ENABLE_MODULES = YES;
185185
CLANG_ENABLE_OBJC_ARC = YES;
186+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
186187
CLANG_WARN_BOOL_CONVERSION = YES;
188+
CLANG_WARN_COMMA = YES;
187189
CLANG_WARN_CONSTANT_CONVERSION = YES;
188190
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
189191
CLANG_WARN_EMPTY_BODY = YES;
190192
CLANG_WARN_ENUM_CONVERSION = YES;
193+
CLANG_WARN_INFINITE_RECURSION = YES;
191194
CLANG_WARN_INT_CONVERSION = YES;
195+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
196+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
192197
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
198+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
199+
CLANG_WARN_STRICT_PROTOTYPES = YES;
200+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
193201
CLANG_WARN_UNREACHABLE_CODE = YES;
194202
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
195203
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -231,13 +239,21 @@
231239
CLANG_CXX_LIBRARY = "libc++";
232240
CLANG_ENABLE_MODULES = YES;
233241
CLANG_ENABLE_OBJC_ARC = YES;
242+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
234243
CLANG_WARN_BOOL_CONVERSION = YES;
244+
CLANG_WARN_COMMA = YES;
235245
CLANG_WARN_CONSTANT_CONVERSION = YES;
236246
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
237247
CLANG_WARN_EMPTY_BODY = YES;
238248
CLANG_WARN_ENUM_CONVERSION = YES;
249+
CLANG_WARN_INFINITE_RECURSION = YES;
239250
CLANG_WARN_INT_CONVERSION = YES;
251+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
252+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
240253
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
254+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
255+
CLANG_WARN_STRICT_PROTOTYPES = YES;
256+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
241257
CLANG_WARN_UNREACHABLE_CODE = YES;
242258
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
243259
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -258,6 +274,7 @@
258274
SDKROOT = iphoneos;
259275
SWIFT_INSTALL_OBJC_HEADER = YES;
260276
SWIFT_OBJC_BRIDGING_HEADER = "WebView Demo for iOS Swift/WebView Demo for iOS Swift-Bridging-Header.h";
277+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
261278
SWIFT_VERSION = 2.3;
262279
VALIDATE_PRODUCT = YES;
263280
};
@@ -274,7 +291,7 @@
274291
PRODUCT_NAME = "WebView Demo for iOS Swift";
275292
SWIFT_OBJC_BRIDGING_HEADER = "WebView Demo for iOS Swift/WebView Demo for iOS Swift-Bridging-Header.h";
276293
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
277-
SWIFT_VERSION = 2.3;
294+
SWIFT_VERSION = 4.0;
278295
TARGETED_DEVICE_FAMILY = "1,2";
279296
};
280297
name = Debug;
@@ -289,7 +306,7 @@
289306
PRODUCT_BUNDLE_IDENTIFIER = "com.agilebits.$(PRODUCT_NAME:rfc1034identifier)";
290307
PRODUCT_NAME = "WebView Demo for iOS Swift";
291308
SWIFT_OBJC_BRIDGING_HEADER = "WebView Demo for iOS Swift/WebView Demo for iOS Swift-Bridging-Header.h";
292-
SWIFT_VERSION = 2.3;
309+
SWIFT_VERSION = 4.0;
293310
TARGETED_DEVICE_FAMILY = "1,2";
294311
};
295312
name = Release;

Demos/WebView Demo for iOS Swift/WebView Demo for iOS Swift/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1717
// Override point for customization after application launch.
1818
return true
1919
}
2020

21-
func applicationWillResignActive(application: UIApplication) {
21+
func applicationWillResignActive(_ application: UIApplication) {
2222
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2323
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2424
}
2525

26-
func applicationDidEnterBackground(application: UIApplication) {
26+
func applicationDidEnterBackground(_ application: UIApplication) {
2727
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2828
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
2929
}
3030

31-
func applicationWillEnterForeground(application: UIApplication) {
31+
func applicationWillEnterForeground(_ application: UIApplication) {
3232
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3333
}
3434

35-
func applicationDidBecomeActive(application: UIApplication) {
35+
func applicationDidBecomeActive(_ application: UIApplication) {
3636
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3737
}
3838

39-
func applicationWillTerminate(application: UIApplication) {
39+
func applicationWillTerminate(_ application: UIApplication) {
4040
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4141
}
4242

Demos/WebView Demo for iOS Swift/WebView Demo for iOS Swift/WebViewController.swift

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)