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

Migrate codebase to Swift 3.0 #345

Merged
merged 12 commits into from
Nov 25, 2016
Merged
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
54 changes: 54 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
- missing_docs
- force_cast
- variable_name
- cyclomatic_complexity
- function_body_length
- todo
opt_in_rules: # some rules are only opt-in
- empty_count
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
- Lock
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 300
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
variable_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit)
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
reference: http://www.objc.io/issue-6/travis-ci.html
language: objective-c
osx_image: xcode8
osx_image: xcode8.1
before_install: true
install: true
script:
Expand All @@ -18,4 +18,4 @@ env:
global:
- secure: hU2sg0N7L2hEAXzmssJRyVGLm1cHKDwuZEE1BQy6y+9jo88926DSTZpw0uLs5h3tHWMctDt/7hoXe9D93oUQowNRaoy6Y/k34VD3Wzfbl2Dht/xZ4M2fgFwy8AYxI9Px3zLmQOewLCsAdFvoLs1rGuRcHy77RH6wtSCMJG/MVng=
after_success:
- bash <(curl -s https://codecov.io/bash) -J 'Lock'
- bash <(curl -s https://codecov.io/bash) -J 'Lock'
5 changes: 3 additions & 2 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return Lock.resumeAuth(url, options: options)
}

}

82 changes: 41 additions & 41 deletions App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ class ViewController: UIViewController {

override func loadView() {
let view = UIView()
view.backgroundColor = .whiteColor()
view.backgroundColor = .white
self.view = view
let header = HeaderView()
header.title = "Welcome to Lock"
header.showClose = false

view.addSubview(header)

NSLayoutConstraint.activateConstraints([
header.leftAnchor.constraintEqualToAnchor(view.leftAnchor),
header.topAnchor.constraintEqualToAnchor(view.topAnchor),
header.rightAnchor.constraintEqualToAnchor(view.rightAnchor),
header.heightAnchor.constraintEqualToConstant(154),
NSLayoutConstraint.activate([
header.leftAnchor.constraint(equalTo: view.leftAnchor),
header.topAnchor.constraint(equalTo: view.topAnchor),
header.rightAnchor.constraint(equalTo: view.rightAnchor),
header.heightAnchor.constraint(equalToConstant: 154),
])
header.translatesAutoresizingMaskIntoConstraints = false

let actions = [
actionButton(withTitle: "LOGIN WITH CDN") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
}
.style {
.withStyle {
$0.oauth2["slack"] = AuthStyle(
name: "Slack",
color: UIColor ( red: 0.4118, green: 0.8078, blue: 0.6588, alpha: 1.0 ),
Expand All @@ -62,12 +62,12 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN WITH CUSTOM STYLE") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
}
.style {
.withStyle {
$0.title = "Phantom Inc."
$0.headerBlur = .ExtraLight
$0.headerBlur = .extraLight
$0.logo = LazyImage(name: "icn_phantom")
$0.primaryColor = UIColor ( red: 0.6784, green: 0.5412, blue: 0.7333, alpha: 1.0 )
}
Expand All @@ -78,7 +78,7 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN WITH DB") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
$0.customSignupFields = [
CustomTextField(name: "first_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)),
Expand All @@ -93,7 +93,7 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN ONLY WITH DB") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
$0.allow = [.Login]
$0.usernameStyle = [.Email]
Expand All @@ -105,7 +105,7 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN WITH DB & SOCIAL") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
}
.withConnections { connections in
Expand All @@ -117,7 +117,7 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN WITH SOCIAL") {
return Lock
.classic()
.options {
.withOptions {
applyDefaultOptions(&$0)
}
.allowedConnections(["facebook", "google-oauth2", "twitter", "dropbox", "bitbucket"])
Expand All @@ -135,51 +135,51 @@ class ViewController: UIViewController {
]

let stack = UIStackView(arrangedSubviews: actions.map { wrap($0) })
stack.axis = .Vertical
stack.distribution = .FillProportionally
stack.alignment = .Fill
stack.axis = .vertical
stack.distribution = .fillProportionally
stack.alignment = .fill

view.addSubview(stack)

NSLayoutConstraint.activateConstraints([
stack.leftAnchor.constraintEqualToAnchor(view.leftAnchor, constant: 18),
stack.topAnchor.constraintEqualToAnchor(header.bottomAnchor),
stack.rightAnchor.constraintEqualToAnchor(view.rightAnchor, constant: -18),
stack.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor),
NSLayoutConstraint.activate([
stack.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 18),
stack.topAnchor.constraint(equalTo: header.bottomAnchor),
stack.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -18),
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
stack.translatesAutoresizingMaskIntoConstraints = false
}

private func actionButton(withTitle title: String, action: () -> Lock) -> AuthButton {
let button = AuthButton(size: .Big)
private func actionButton(withTitle title: String, action: @escaping () -> Lock) -> AuthButton {
let button = AuthButton(size: .big)
button.title = title
button.onPress = { [weak self] _ in
self?.showLock(action())
}
return button
}

private func wrap(button: AuthButton) -> UIView {
private func wrap(_ button: AuthButton) -> UIView {
let wrapper = UIView()
wrapper.backgroundColor = .whiteColor()
wrapper.backgroundColor = .white
wrapper.addSubview(button)

button.leftAnchor.constraintEqualToAnchor(wrapper.leftAnchor).active = true
button.rightAnchor.constraintEqualToAnchor(wrapper.rightAnchor).active = true
button.centerYAnchor.constraintEqualToAnchor(wrapper.centerYAnchor).active = true
button.leftAnchor.constraint(equalTo: wrapper.leftAnchor).isActive = true
button.rightAnchor.constraint(equalTo: wrapper.rightAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: wrapper.centerYAnchor).isActive = true
button.translatesAutoresizingMaskIntoConstraints = false

return wrapper
}

private func showLock(lock: Lock) {
private func showLock(_ lock: Lock) {
Log.enable(minimumSeverity: LogSeverity.verbose)
lock
.on { result in
switch result {
case .Success(let credentials):
case .success(let credentials):
Log.info?.message("Obtained credentials \(credentials)")
case .Failure(let cause):
case .failure(let cause):
Log.error?.message("Failed with \(cause)")
default:
Log.debug?.value(result)
Expand All @@ -189,27 +189,27 @@ class ViewController: UIViewController {
}
}

private func applyDefaultOptions(inout options: OptionBuildable) {
func applyDefaultOptions(_ options: inout OptionBuildable) {
options.closable = true
options.logLevel = .All
options.logLevel = .all
options.loggerOutput = CleanroomLockLogger()
options.logHttpRequest = true
}

class CleanroomLockLogger: LoggerOutput {

func message(message: String, level: LoggerLevel, filename: String, line: Int) {
func message(_ message: String, level: LoggerLevel, filename: String, line: Int) {
let channel: LogChannel?
switch level {
case .Debug:
case .debug:
channel = Log.debug
case .Error:
case .error:
channel = Log.error
case .Info:
case .info:
channel = Log.info
case .Verbose:
case .verbose:
channel = Log.verbose
case .Warn:
case .warn:
channel = Log.warning
default:
channel = nil
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "auth0/Auth0.swift" "v1@swift-2.3"
github "auth0/Auth0.swift" ~> 1.0
8 changes: 4 additions & 4 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "Quick/Quick" ~> 0.9
github "Quick/Nimble" ~> 4.0
github "AliSoftware/OHHTTPStubs" ~> 5.0
github "emaloney/CleanroomLogger" "2.2.0"
github "Quick/Quick" ~> 1.0
github "Quick/Nimble" ~> 5.1
github "AliSoftware/OHHTTPStubs" "5.2.2-swift3"
github "emaloney/CleanroomLogger" "3.0.0"
12 changes: 6 additions & 6 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github "auth0/Auth0.swift" "a91d2d29adadc698d2288c65559f161a37537c05"
github "emaloney/CleanroomASL" "1.5.0"
github "Quick/Nimble" "v4.1.0"
github "AliSoftware/OHHTTPStubs" "5.2.1"
github "Quick/Quick" "v0.9.3"
github "emaloney/CleanroomLogger" "2.2.0"
github "auth0/Auth0.swift" "1.0.1"
github "emaloney/CleanroomASL" "2.0.0"
github "Quick/Nimble" "v5.1.1"
github "AliSoftware/OHHTTPStubs" "5.2.2-swift3"
github "Quick/Quick" "v1.0.0"
github "emaloney/CleanroomLogger" "3.0.0"
Loading