Skip to content

Commit fd7eace

Browse files
authored
Merge pull request #186 from mattrubin/xcode-8.3
Convert to Swift 3
2 parents f58085d + 45de0b9 commit fd7eace

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1039
-1069
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ language: objective-c
55
xcode_workspace: Authenticator.xcworkspace
66
xcode_scheme: Authenticator
77

8-
osx_image: xcode8.2
8+
osx_image: xcode8.3
99

1010
env:
1111
- RUNTIME="iOS 8.2" DEVICE="iPhone 4s"
1212
- RUNTIME="iOS 8.4" DEVICE="iPhone 5s"
1313
- RUNTIME="iOS 9.3" DEVICE="iPhone 6s"
14-
- RUNTIME="iOS 10.2" DEVICE="iPhone 7 Plus"
14+
- RUNTIME="iOS 10.3" DEVICE="iPhone 7 Plus"
1515

1616
install:
1717
- git submodule update --init --recursive

Authenticator.xcodeproj/project.pbxproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@
570570
TargetAttributes = {
571571
1D6058900D05DD3D006BFB54 = {
572572
DevelopmentTeam = WD7ETSN9J9;
573-
LastSwiftMigration = 0800;
573+
LastSwiftMigration = 0830;
574574
ProvisioningStyle = Automatic;
575575
};
576576
C9906A2D1812522100BAEF53 = {
577-
LastSwiftMigration = 0800;
577+
LastSwiftMigration = 0830;
578578
TestTargetID = 1D6058900D05DD3D006BFB54;
579579
};
580580
C9A262CC1E170BD4004E6CEB = {
@@ -766,7 +766,7 @@
766766
);
767767
GCC_DYNAMIC_NO_PIC = NO;
768768
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
769-
SWIFT_VERSION = 2.3;
769+
SWIFT_VERSION = 3.0;
770770
};
771771
name = Debug;
772772
};
@@ -781,7 +781,7 @@
781781
);
782782
GCC_DYNAMIC_NO_PIC = NO;
783783
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
784-
SWIFT_VERSION = 2.3;
784+
SWIFT_VERSION = 3.0;
785785
};
786786
name = Release;
787787
};
@@ -812,7 +812,6 @@
812812
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
813813
PRODUCT_BUNDLE_IDENTIFIER = me.mattrubin.authenticator.screenshots;
814814
PRODUCT_NAME = "$(TARGET_NAME)";
815-
SWIFT_VERSION = 3.0;
816815
TEST_TARGET_NAME = Authenticator;
817816
};
818817
name = Debug;
@@ -824,7 +823,6 @@
824823
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
825824
PRODUCT_BUNDLE_IDENTIFIER = me.mattrubin.authenticator.screenshots;
826825
PRODUCT_NAME = "$(TARGET_NAME)";
827-
SWIFT_VERSION = 3.0;
828826
TEST_TARGET_NAME = Authenticator;
829827
};
830828
name = Release;

Authenticator/Source/AppController.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AppController {
3434
private var component: Root {
3535
didSet {
3636
// TODO: Fix the excessive updates of bar button items so that the tick can run while they are on screen.
37-
if case .None = component.viewModel.modal {
37+
if case .none = component.viewModel.modal {
3838
if displayLink == nil {
3939
startTick()
4040
}
@@ -55,13 +55,13 @@ class AppController {
5555

5656
init() {
5757
do {
58-
if Process.isDemo {
58+
if CommandLine.isDemo {
5959
// If this is a demo, use a token store of mock data, not backed by the keychain.
6060
store = DemoTokenStore()
6161
} else {
6262
store = try KeychainTokenStore(
6363
keychain: Keychain.sharedInstance,
64-
userDefaults: NSUserDefaults.standardUserDefaults()
64+
userDefaults: UserDefaults.standard
6565
)
6666
}
6767
} catch {
@@ -70,7 +70,7 @@ class AppController {
7070
}
7171

7272
// If this is a demo, show the scanner even in the simulator.
73-
let deviceCanScan = QRScanner.deviceCanScan || Process.isDemo
73+
let deviceCanScan = QRScanner.deviceCanScan || CommandLine.isDemo
7474
component = Root(
7575
persistentTokens: store.persistentTokens,
7676
displayTime: .currentDisplayTime(),
@@ -87,7 +87,7 @@ class AppController {
8787
private func startTick() {
8888
let selector = #selector(tick)
8989
self.displayLink = CADisplayLink(target: self, selector: selector)
90-
self.displayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
90+
self.displayLink?.add(to: RunLoop.main, forMode: .commonModes)
9191
}
9292

9393
private func stopTick() {
@@ -98,12 +98,12 @@ class AppController {
9898
@objc
9999
func tick() {
100100
// Dispatch an event to trigger a view model update.
101-
handleEvent(.UpdateDisplayTime(.currentDisplayTime()))
101+
handleEvent(.updateDisplayTime(.currentDisplayTime()))
102102
}
103103

104104
// MARK: - Update
105105

106-
private func handleAction(action: Root.Action) {
106+
private func handleAction(_ action: Root.Action) {
107107
do {
108108
let sideEffect = try component.update(action)
109109
if let effect = sideEffect {
@@ -114,65 +114,65 @@ class AppController {
114114
}
115115
}
116116

117-
private func handleEvent(event: Root.Event) {
117+
private func handleEvent(_ event: Root.Event) {
118118
let sideEffect = component.update(event)
119119
if let effect = sideEffect {
120120
handleEffect(effect)
121121
}
122122
}
123123

124-
private func handleEffect(effect: Root.Effect) {
124+
private func handleEffect(_ effect: Root.Effect) {
125125
switch effect {
126-
case let .AddToken(token, success, failure):
126+
case let .addToken(token, success, failure):
127127
do {
128128
try store.addToken(token)
129129
handleEvent(success(store.persistentTokens))
130130
} catch {
131131
handleEvent(failure(error))
132132
}
133133

134-
case let .SaveToken(token, persistentToken, success, failure):
134+
case let .saveToken(token, persistentToken, success, failure):
135135
do {
136136
try store.saveToken(token, toPersistentToken: persistentToken)
137137
handleEvent(success(store.persistentTokens))
138138
} catch {
139139
handleEvent(failure(error))
140140
}
141141

142-
case let .UpdatePersistentToken(persistentToken, success, failure):
142+
case let .updatePersistentToken(persistentToken, success, failure):
143143
do {
144144
try store.updatePersistentToken(persistentToken)
145145
handleEvent(success(store.persistentTokens))
146146
} catch {
147147
handleEvent(failure(error))
148148
}
149149

150-
case let .MoveToken(fromIndex, toIndex, success):
150+
case let .moveToken(fromIndex, toIndex, success):
151151
store.moveTokenFromIndex(fromIndex, toIndex: toIndex)
152152
handleEvent(success(store.persistentTokens))
153153

154-
case let .DeletePersistentToken(persistentToken, success, failure):
154+
case let .deletePersistentToken(persistentToken, success, failure):
155155
do {
156156
try store.deletePersistentToken(persistentToken)
157157
handleEvent(success(store.persistentTokens))
158158
} catch {
159159
handleEvent(failure(error))
160160
}
161161

162-
case let .ShowErrorMessage(message):
163-
SVProgressHUD.showErrorWithStatus(message)
162+
case let .showErrorMessage(message):
163+
SVProgressHUD.showError(withStatus: message)
164164

165-
case let .ShowSuccessMessage(message):
166-
SVProgressHUD.showSuccessWithStatus(message)
165+
case let .showSuccessMessage(message):
166+
SVProgressHUD.showSuccess(withStatus: message)
167167

168-
case let .OpenURL(url):
168+
case let .openURL(url):
169169
if #available(iOS 9.0, *) {
170-
let safariViewController = SFSafariViewController(URL: url)
170+
let safariViewController = SFSafariViewController(url: url)
171171
let presenter = topViewController(presentedFrom: rootViewController)
172-
presenter.presentViewController(safariViewController, animated: true, completion: nil)
172+
presenter.present(safariViewController, animated: true)
173173
} else {
174174
// Fallback on earlier versions
175-
UIApplication.sharedApplication().openURL(url)
175+
UIApplication.shared.openURL(url)
176176
}
177177
}
178178
}
@@ -190,17 +190,17 @@ class AppController {
190190
return view
191191
}
192192

193-
func addTokenFromURL(token: Token) {
194-
handleAction(.AddTokenFromURL(token))
193+
func addTokenFromURL(_ token: Token) {
194+
handleAction(.addTokenFromURL(token))
195195
}
196196
}
197197

198198
private extension DisplayTime {
199199
static func currentDisplayTime() -> DisplayTime {
200-
if Process.isDemo {
200+
if CommandLine.isDemo {
201201
// If this is a demo, use a constant time.
202202
return DisplayTime.demoTime
203203
}
204-
return DisplayTime(date: NSDate())
204+
return DisplayTime(date: Date())
205205
}
206206
}

Authenticator/Source/BarButtonViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
//
2525

2626
enum BarButtonStyle {
27-
case Done
28-
case Cancel
27+
case done
28+
case cancel
2929
}
3030

3131
struct BarButtonViewModel<Action> {

Authenticator/Source/ButtonHeaderView.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,27 @@ class ButtonHeaderView<Action>: UIButton {
5656
// MARK: - Subviews
5757

5858
private func configureSubviews() {
59-
titleLabel?.textAlignment = .Center
59+
titleLabel?.textAlignment = .center
6060
titleLabel?.textColor = UIColor.otpForegroundColor
61-
titleLabel?.font = UIFont.systemFontOfSize(16, weight: UIFontWeightLight)
61+
titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightLight)
6262

63-
let action = #selector(ButtonHeaderView.buttonWasPressed)
64-
addTarget(self, action: action, forControlEvents: .TouchUpInside)
63+
addTarget(self, action: #selector(ButtonHeaderView.buttonWasPressed), for: .touchUpInside)
6564
}
6665

6766
// MARK: - View Model
6867

69-
convenience init(viewModel: ButtonHeaderViewModel<Action>, dispatchAction: (Action) -> Void) {
68+
convenience init(viewModel: ButtonHeaderViewModel<Action>, dispatchAction: @escaping (Action) -> Void) {
7069
self.init()
7170
self.dispatchAction = dispatchAction
7271
updateWithViewModel(viewModel)
7372
}
7473

75-
func updateWithViewModel(viewModel: ButtonHeaderViewModel<Action>) {
76-
setTitle(viewModel.title, forState: .Normal)
74+
func updateWithViewModel(_ viewModel: ButtonHeaderViewModel<Action>) {
75+
setTitle(viewModel.title, for: .normal)
7776
buttonAction = viewModel.action
7877
}
7978

80-
static func heightWithViewModel(viewModel: ButtonHeaderViewModel<Action>) -> CGFloat {
79+
static func heightWithViewModel(_ viewModel: ButtonHeaderViewModel<Action>) -> CGFloat {
8180
return preferredHeight
8281
}
8382

Authenticator/Source/Component.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ protocol Component {
3131
// MARK: Update
3232
associatedtype Action
3333
associatedtype Effect
34-
mutating func update(action: Action) throws -> Effect?
34+
mutating func update(_ action: Action) throws -> Effect?
3535
}
3636

37-
struct ComponentError<C: Component>: ErrorType {
38-
let underlyingError: ErrorType
37+
struct ComponentError<C: Component>: Error {
38+
let underlyingError: Error
3939
let action: C.Action
4040
let component: C
4141
}

0 commit comments

Comments
 (0)