Skip to content

Commit

Permalink
Added Swift 3.2/4.0 Compatibility (#480)
Browse files Browse the repository at this point in the history
Migrated to Swift 4 / Set 3.2
Update README
Update Gems
Update Circle CI Xcode 9.2
  • Loading branch information
cocojoe committed Jan 5, 2018
1 parent 130481c commit 78a4ec5
Show file tree
Hide file tree
Showing 36 changed files with 164 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build-and-test:
macos:
xcode: "9.0"
xcode: "9.2.0"

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
3.2
14 changes: 9 additions & 5 deletions App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="17C88" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -13,9 +17,9 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github "AliSoftware/OHHTTPStubs" "6.0.0"
github "Quick/Nimble" "v7.0.2"
github "AliSoftware/OHHTTPStubs" "6.1.0"
github "Quick/Nimble" "v7.0.3"
github "Quick/Quick" "v1.2.0"
github "auth0/Auth0.swift" "1.9.1"
github "auth0/Auth0.swift" "1.9.2"
github "auth0/SimpleKeychain" "0.8.0"
github "emaloney/CleanroomLogger" "5.1.2"
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.5)
CFPropertyList (2.3.6)
activesupport (4.2.10)
i18n (~> 0.7)
minitest (~> 5.1)
Expand Down Expand Up @@ -64,7 +64,7 @@ GEM
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.0)
fastlane (2.64.1)
fastlane (2.68.2)
CFPropertyList (>= 2.3, < 3.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
Expand Down Expand Up @@ -92,7 +92,7 @@ GEM
slack-notifier (>= 1.3, < 2.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (~> 0.5.0)
tty-screen (~> 0.6.2)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.5.2, < 2.0.0)
xcpretty (>= 0.2.4, < 1.0.0)
Expand All @@ -117,7 +117,7 @@ GEM
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
highline (1.7.8)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
Expand All @@ -143,7 +143,7 @@ GEM
nap (1.1.0)
netrc (0.11.0)
os (0.9.6)
plist (3.3.0)
plist (3.4.0)
public_suffix (2.0.5)
representable (3.0.4)
declarative (< 0.1.0)
Expand All @@ -165,7 +165,7 @@ GEM
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6)
tty-screen (0.5.1)
tty-screen (0.6.3)
tzinfo (1.2.4)
thread_safe (~> 0.1)
uber (0.1.0)
Expand Down
1 change: 0 additions & 1 deletion Lock.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Auth0 is a SaaS that helps you with Authentication and Authorization. You can us

s.requires_arc = true


s.dependency 'Auth0', '~> 1.9'
s.default_subspecs = 'Classic'

Expand Down
24 changes: 18 additions & 6 deletions Lock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,13 @@
TargetAttributes = {
5BEDE1391EC0A9750007300D = {
CreatedOnToolsVersion = 8.3.2;
ProvisioningStyle = Automatic;
ProvisioningStyle = Manual;
TestTargetID = 5FEADCF31D1A7EBC0032D810;
};
5FEADCF31D1A7EBC0032D810 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 86WQXF56BC;
LastSwiftMigration = 0810;
LastSwiftMigration = 0920;
ProvisioningStyle = Manual;
SystemCapabilities = {
com.apple.SafariKeychain = {
Expand All @@ -1025,11 +1025,11 @@
};
5FEAE1C51D1A5154005C0028 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0820;
LastSwiftMigration = 0920;
};
5FEAE1CF1D1A5154005C0028 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0810;
LastSwiftMigration = 0920;
ProvisioningStyle = Manual;
TestTargetID = 5FEADCF31D1A7EBC0032D810;
};
Expand Down Expand Up @@ -1381,12 +1381,15 @@
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LockUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.LockUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "97f7985c-a5ce-42be-a3e5-39a6c818bc78";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = LockApp;
Expand All @@ -1398,12 +1401,15 @@
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LockUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.LockUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "97f7985c-a5ce-42be-a3e5-39a6c818bc78";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = LockApp;
};
Expand All @@ -1428,6 +1434,7 @@
PROVISIONING_PROFILE = "97f7985c-a5ce-42be-a3e5-39a6c818bc78";
PROVISIONING_PROFILE_SPECIFIER = "match Development com.auth0.Lock";
REEXPORTED_LIBRARY_PATHS = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
};
name = Debug;
Expand All @@ -1451,6 +1458,7 @@
PROVISIONING_PROFILE = "97f7985c-a5ce-42be-a3e5-39a6c818bc78";
PROVISIONING_PROFILE_SPECIFIER = "match Development com.auth0.Lock";
REEXPORTED_LIBRARY_PATHS = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
};
name = Release;
Expand Down Expand Up @@ -1586,6 +1594,7 @@
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
};
name = Debug;
Expand All @@ -1611,6 +1620,7 @@
PRODUCT_NAME = Lock;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
};
name = Release;
Expand All @@ -1627,6 +1637,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.LockTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LockApp.app/LockApp";
};
Expand All @@ -1644,6 +1655,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.LockTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LockApp.app/LockApp";
};
Expand Down
4 changes: 2 additions & 2 deletions Lock/AuthButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class AuthButton: UIView {
button.setBackgroundImage(image(withColor: self.color), for: UIControlState())
button.setBackgroundImage(image(withColor: self.color.a0_darker(0.3)), for: .highlighted)
button.setTitleColor(self.titleColor, for: UIControlState())
button.titleLabel?.font = .systemFont(ofSize: 13.33, weight: UIFontWeightMedium)
button.titleLabel?.font = .systemFont(ofSize: 13.33, weight: UIFont.weightMedium)
button.titleLabel?.adjustsFontSizeToFitWidth = true
button.titleLabel?.minimumScaleFactor = 0.5
button.contentVerticalAlignment = .center
Expand Down Expand Up @@ -184,7 +184,7 @@ public class AuthButton: UIView {

// MARK: - Event

func buttonPressed(_ sender: Any) {
@objc func buttonPressed(_ sender: Any) {
self.onPress(self)
}
}
Expand Down
8 changes: 6 additions & 2 deletions Lock/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@

import UIKit

extension UIColor {
public extension UIColor {

static var a0_orange: UIColor { return UIColor ( red: 0.9176, green: 0.3255, blue: 0.1373, alpha: 1.0 ) }
public static var a0_orange: UIColor { return UIColor ( red: 0.9176, green: 0.3255, blue: 0.1373, alpha: 1.0 ) }

static func a0_fromRGB(_ string: String, defaultColor: UIColor = .a0_orange) -> UIColor {
guard string.hasPrefix("#") else { return defaultColor }

#if swift(>=3.2)
let hexString: String = String(string[string.index(string.startIndex, offsetBy: 1)...])
#else
let hexString: String = string.substring(from: string.characters.index(string.startIndex, offsetBy: 1))
#endif
var hexValue: UInt32 = 0

guard Scanner(string: hexString).scanHexInt32(&hexValue) else {
Expand Down
2 changes: 1 addition & 1 deletion Lock/CountryTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CountryTableViewController: UITableViewController, Stylable {
fatalError("init(coder:) has not been implemented")
}

func close() {
@objc func close() {
self.dismiss(animated: true, completion: nil)
}

Expand Down
2 changes: 1 addition & 1 deletion Lock/CustomTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct CustomTextField {
}
}

private func nonEmpty(_ value: String?) -> Error? {
public func nonEmpty(_ value: String?) -> Error? {
guard let username = value?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines), !username.isEmpty else { return InputValidationError.mustNotBeEmpty }
return nil
}
18 changes: 9 additions & 9 deletions Lock/DatabaseModeSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class DatabaseModeSwitcher: UIView {
segmented.setBackgroundImage(image(named: "ic_switcher_selected", compatibleWithTraitCollection: self.traitCollection), for: .highlighted, barMetrics: .default)
segmented.setBackgroundImage(image(named: "ic_switcher_normal", compatibleWithTraitCollection: self.traitCollection), for: UIControlState(), barMetrics: .default)
segmented.setTitleTextAttributes([
NSForegroundColorAttributeName: Style.Auth0.tabTextColor,
NSFontAttributeName: mediumSystemFont(size: 15)
attributedKeyColor: Style.Auth0.tabTextColor,
attributedFont: mediumSystemFont(size: 15)
], for: UIControlState())
segmented.setTitleTextAttributes([
NSForegroundColorAttributeName: Style.Auth0.tabTextColor,
NSFontAttributeName: semiBoldSystemFont(size: 15)
attributedKeyColor: Style.Auth0.tabTextColor,
attributedFont: semiBoldSystemFont(size: 15)
], for: .selected)
segmented.tintColor = Style.Auth0.tabTintColor
segmented.addTarget(self, action: #selector(selectedIndex), for: .valueChanged)
Expand All @@ -114,7 +114,7 @@ class DatabaseModeSwitcher: UIView {

// MARK: - Internal

func selectedIndex(_ sender: UISegmentedControl) {
@objc func selectedIndex(_ sender: UISegmentedControl) {
self.onSelectionChange(self)
}
}
Expand All @@ -124,12 +124,12 @@ extension DatabaseModeSwitcher: Stylable {
func apply(style: Style) {
self.segmentedControl?.tintColor = style.tabTintColor
self.segmentedControl?.setTitleTextAttributes([
NSForegroundColorAttributeName: style.tabTextColor,
NSFontAttributeName: mediumSystemFont(size: 15)
attributedKeyColor: style.tabTextColor,
attributedFont: mediumSystemFont(size: 15)
], for: UIControlState())
self.segmentedControl?.setTitleTextAttributes([
NSForegroundColorAttributeName: style.tabTextColor,
NSFontAttributeName: semiBoldSystemFont(size: 15)
attributedKeyColor: style.tabTextColor,
attributedFont: semiBoldSystemFont(size: 15)
], for: .selected)
}
}
34 changes: 34 additions & 0 deletions Lock/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,37 @@ extension UIView {
}
}
}

extension UILayoutPriority {
#if swift(>=4.0)
static let priorityRequired = UILayoutPriority.required
static let priorityDefaultLow = UILayoutPriority.defaultLow
static let priorityDefaultHigh = UILayoutPriority.defaultHigh
#else
static let priorityRequired = UILayoutPriorityRequired
static let priorityDefaultLow = UILayoutPriorityDefaultLow
static let priorityDefaultHigh = UILayoutPriorityDefaultHigh
#endif
}

#if swift(>=4.0)
let attributedKeyColor = NSAttributedStringKey.foregroundColor
let attributedFont = NSAttributedStringKey.font
#else
let attributedKeyColor = NSForegroundColorAttributeName
let attributedFont = NSFontAttributeName
#endif

extension UIFont {
#if swift(>=4.0)
static let weightLight = UIFont.Weight.light
static let weightMedium = UIFont.Weight.medium
static let weightRegular = UIFont.Weight.regular
static let weightSemiBold = UIFont.Weight.semibold
#else
static let weightLight = UIFontWeightLight
static let weightMedium = UIFontWeightMedium
static let weightRegular = UIFontWeightRegular
static let weightSemiBold = UIFontWeightSemibold
#endif
}
6 changes: 3 additions & 3 deletions Lock/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public class HeaderView: UIView {

constraintEqual(anchor: titleView.bottomAnchor, toAnchor: centerGuide.bottomAnchor)
constraintEqual(anchor: titleView.centerXAnchor, toAnchor: centerGuide.centerXAnchor)
titleView.setContentCompressionResistancePriority(UILayoutPriorityRequired, for: .horizontal)
titleView.setContentHuggingPriority(UILayoutPriorityRequired, for: .horizontal)
titleView.setContentCompressionResistancePriority(UILayoutPriority.priorityRequired, for: .horizontal)
titleView.setContentHuggingPriority(UILayoutPriority.priorityRequired, for: .horizontal)
titleView.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: logoView.centerXAnchor, toAnchor: self.centerXAnchor)
Expand Down Expand Up @@ -184,7 +184,7 @@ public class HeaderView: UIView {
return CGSize(width: 200, height: 154)
}

func buttonPressed(_ sender: UIButton) {
@objc func buttonPressed(_ sender: UIButton) {
if sender == self.backButton {
self.onBackPressed()
}
Expand Down
2 changes: 1 addition & 1 deletion Lock/IconButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class IconButton: UIView {
self.button = button
}

func pressed(_ sender: Any) {
@objc func pressed(_ sender: Any) {
self.onPress(self)
}

Expand Down
Loading

0 comments on commit 78a4ec5

Please sign in to comment.