Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Xcode 10, Swift 4.2 #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.2
6 changes: 5 additions & 1 deletion Example/SwiftWebVCExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Myles Ringle";
TargetAttributes = {
00FFF8541E09977500015C59 = {
Expand Down Expand Up @@ -269,13 +269,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -326,13 +328,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
22 changes: 16 additions & 6 deletions Example/SwiftWebVCExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="zaI-sO-1Yv">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="zaI-sO-1Yv">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -38,7 +38,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QSh-Xk-40Y">
<rect key="frame" x="34" y="319.5" width="307" height="28"/>
<rect key="frame" x="33.5" y="319.5" width="308" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Google.com With Default Theme (Light Blue)"/>
<connections>
Expand All @@ -52,21 +52,31 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8ec-UK-JwU">
<rect key="frame" x="112" y="233.5" width="152" height="28"/>
<rect key="frame" x="61.5" y="233.5" width="253" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Google.com Without Toolbar (Push)"/>
<connections>
<action selector="pushWithoutToolBar" destination="bLx-fa-uWl" eventType="touchUpInside" id="OSF-1T-Kbr"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HY0-HN-b4h">
<rect key="frame" x="111" y="185.5" width="153" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Google.com (Push)"/>
<connections>
<action selector="push" destination="bLx-fa-uWl" eventType="touchUpInside" id="7ei-rv-Ow1"/>
<action selector="push" destination="bLx-fa-uWl" eventType="touchUpInside" id="4Kc-M6-ytC"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="k3S-Y4-F4d" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="964-EK-xal"/>
<constraint firstItem="E22-Wf-Eov" firstAttribute="top" secondItem="QSh-Xk-40Y" secondAttribute="bottom" constant="20" id="9Rc-Ia-roS"/>
<constraint firstItem="8ec-UK-JwU" firstAttribute="top" secondItem="HY0-HN-b4h" secondAttribute="bottom" constant="20" id="9yb-JA-KOK"/>
<constraint firstItem="QSh-Xk-40Y" firstAttribute="centerY" secondItem="bXY-Xx-qq8" secondAttribute="centerY" id="AKe-Ro-lFE"/>
<constraint firstItem="QSh-Xk-40Y" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="MkB-QK-YWL"/>
<constraint firstItem="8ec-UK-JwU" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="Nru-Ws-bMg"/>
<constraint firstItem="HY0-HN-b4h" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="RHb-R1-DCa"/>
<constraint firstItem="081-aS-c8D" firstAttribute="top" secondItem="8ec-UK-JwU" secondAttribute="bottom" constant="34" id="a5j-rN-XVI"/>
<constraint firstItem="QSh-Xk-40Y" firstAttribute="top" secondItem="081-aS-c8D" secondAttribute="bottom" constant="8" id="cJl-nW-KQw"/>
<constraint firstItem="k3S-Y4-F4d" firstAttribute="top" secondItem="E22-Wf-Eov" secondAttribute="bottom" constant="20" id="gz9-W9-QQR"/>
Expand All @@ -86,7 +96,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="zaI-sO-1Yv" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="heT-aK-khc">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
7 changes: 7 additions & 0 deletions Example/SwiftWebVCExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class ViewController: UIViewController {
@IBAction func push() {
let webVC = SwiftWebVC(urlString: "https://www.google.com")
webVC.delegate = self
webVC.title = "test title"
self.navigationController?.pushViewController(webVC, animated: true)
}

@IBAction func pushWithoutToolBar() {
let webVC = SwiftWebVC(urlString: "https://www.google.com", hideToolBar: true)
webVC.delegate = self
self.navigationController?.pushViewController(webVC, animated: true)
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftWebVC/SwiftModalWebVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SwiftModalWebVC: UINavigationController {

let dismissButtonImageName = (dismissButtonStyle == .arrow) ? "SwiftWebVCDismiss" : "SwiftWebVCDismissAlt"
let doneButton = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: dismissButtonImageName),
style: UIBarButtonItemStyle.plain,
style: UIBarButtonItem.Style.plain,
target: webViewController,
action: #selector(SwiftWebVC.doneButtonTapped))

Expand Down
52 changes: 32 additions & 20 deletions SwiftWebVC/SwiftWebVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SwiftWebVC: UIViewController {

lazy var backBarButtonItem: UIBarButtonItem = {
var tempBackBarButtonItem = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: "SwiftWebVCBack"),
style: UIBarButtonItemStyle.plain,
style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(SwiftWebVC.goBackTapped(_:)))
tempBackBarButtonItem.width = 18.0
Expand All @@ -33,7 +33,7 @@ public class SwiftWebVC: UIViewController {

lazy var forwardBarButtonItem: UIBarButtonItem = {
var tempForwardBarButtonItem = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: "SwiftWebVCNext"),
style: UIBarButtonItemStyle.plain,
style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(SwiftWebVC.goForwardTapped(_:)))
tempForwardBarButtonItem.width = 18.0
Expand All @@ -42,23 +42,23 @@ public class SwiftWebVC: UIViewController {
}()

lazy var refreshBarButtonItem: UIBarButtonItem = {
var tempRefreshBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.refresh,
var tempRefreshBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.refresh,
target: self,
action: #selector(SwiftWebVC.reloadTapped(_:)))
tempRefreshBarButtonItem.tintColor = self.buttonColor
return tempRefreshBarButtonItem
}()

lazy var stopBarButtonItem: UIBarButtonItem = {
var tempStopBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.stop,
var tempStopBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.stop,
target: self,
action: #selector(SwiftWebVC.stopTapped(_:)))
tempStopBarButtonItem.tintColor = self.buttonColor
return tempStopBarButtonItem
}()

lazy var actionBarButtonItem: UIBarButtonItem = {
var tempActionBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action,
var tempActionBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.action,
target: self,
action: #selector(SwiftWebVC.actionButtonTapped(_:)))
tempActionBarButtonItem.tintColor = self.buttonColor
Expand All @@ -79,6 +79,8 @@ public class SwiftWebVC: UIViewController {

var sharingEnabled = true

var hideToolBar: Bool = false

////////////////////////////////////////////////

deinit {
Expand All @@ -88,22 +90,23 @@ public class SwiftWebVC: UIViewController {
webView.navigationDelegate = nil;
}

public convenience init(urlString: String, sharingEnabled: Bool = true) {
public convenience init(urlString: String, sharingEnabled: Bool = true, hideToolBar: Bool = false) {
var urlString = urlString
if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") {
urlString = "https://"+urlString
}
self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled)
self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled, hideToolBar: hideToolBar)
}

public convenience init(pageURL: URL, sharingEnabled: Bool = true) {
self.init(aRequest: URLRequest(url: pageURL), sharingEnabled: sharingEnabled)
public convenience init(pageURL: URL, sharingEnabled: Bool = true, hideToolBar: Bool = false) {
self.init(aRequest: URLRequest(url: pageURL), sharingEnabled: sharingEnabled, hideToolBar: hideToolBar)
}

public convenience init(aRequest: URLRequest, sharingEnabled: Bool = true) {
public convenience init(aRequest: URLRequest, sharingEnabled: Bool = true, hideToolBar: Bool = false) {
self.init()
self.sharingEnabled = sharingEnabled
self.request = aRequest
self.hideToolBar = hideToolBar
}

func loadRequest(_ request: URLRequest) {
Expand All @@ -129,8 +132,9 @@ public class SwiftWebVC: UIViewController {
navBarTitle = UILabel()
navBarTitle.backgroundColor = UIColor.clear
if presentingViewController == nil {
if let titleAttributes = navigationController!.navigationBar.titleTextAttributes {
navBarTitle.textColor = titleAttributes[.foregroundColor] as? UIColor

if let titleAttributes = navigationController!.navigationBar.titleTextAttributes as [NSAttributedString.Key : Any]? {
navBarTitle.textColor = titleAttributes[NSAttributedString.Key.foregroundColor] as? UIColor
}
}
else {
Expand All @@ -144,7 +148,7 @@ public class SwiftWebVC: UIViewController {
super.viewWillAppear(true)

if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone) {
self.navigationController?.setToolbarHidden(false, animated: false)
self.navigationController?.setToolbarHidden(self.hideToolBar, animated: false)
}
else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
self.navigationController?.setToolbarHidden(true, animated: true)
Expand All @@ -168,13 +172,16 @@ public class SwiftWebVC: UIViewController {
// Toolbar

func updateToolbarItems() {
guard hideToolBar == false else {
return
}
backBarButtonItem.isEnabled = webView.canGoBack
forwardBarButtonItem.isEnabled = webView.canGoForward

let refreshStopBarButtonItem: UIBarButtonItem = webView.isLoading ? stopBarButtonItem : refreshBarButtonItem

let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
let flexibleSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.fixedSpace, target: nil, action: nil)
let flexibleSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)

if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {

Expand Down Expand Up @@ -297,13 +304,18 @@ extension SwiftWebVC: WKNavigationDelegate {
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.delegate?.didFinishLoading(success: true)
UIApplication.shared.isNetworkActivityIndicatorVisible = false
webView.evaluateJavaScript("document.title", completionHandler: {(response, error) in
self.navBarTitle.text = response as! String?

if let title = self.title {
self.navBarTitle.text = title
self.navBarTitle.sizeToFit()
self.updateToolbarItems()
})

}else{
webView.evaluateJavaScript("document.title", completionHandler: {(response, error) in
self.navBarTitle.text = response as! String?
self.navBarTitle.sizeToFit()
self.updateToolbarItems()
})
}
}

public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
Expand Down
4 changes: 2 additions & 2 deletions SwiftWebVC/SwiftWebVCActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class SwiftWebVCActivity: UIActivity {
var URLToOpen: URL?
var schemePrefix: String?

override var activityType : UIActivityType? {
override var activityType : UIActivity.ActivityType? {
let typeArray = "\(type(of: self))".components(separatedBy: ".")
let _type: String = typeArray[typeArray.count-1]
return UIActivityType(rawValue: _type)
return UIActivity.ActivityType(rawValue: _type)
}

override var activityImage : UIImage {
Expand Down
4 changes: 2 additions & 2 deletions SwiftWebVC/SwiftWebVCActivityChrome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SwiftWebVCActivityChrome : SwiftWebVCActivity {
}

override func perform() {
let inputURL: URL! = URLToOpen as URL!
let inputURL: URL! = URLToOpen as URL?
let scheme: String! = inputURL.scheme

// Replace the URL Scheme with the Chrome equivalent.
Expand All @@ -38,7 +38,7 @@ class SwiftWebVCActivityChrome : SwiftWebVCActivity {

// Proceed only if a valid Google Chrome URI Scheme is available.
if chromeScheme != nil {
let absoluteString: NSString! = inputURL!.absoluteString as NSString!
let absoluteString: NSString! = inputURL!.absoluteString as NSString?
let rangeForScheme: NSRange! = absoluteString.range(of: ":")
let urlNoScheme: String! = absoluteString.substring(from: rangeForScheme.location)
let chromeURLString: String! = chromeScheme!+urlNoScheme
Expand Down
Loading