Skip to content

Commit ea24036

Browse files
sgoodwinsidraval
authored andcommitted
Support Swift 5.0 (#123)
* Update Swish for Swift 5.0. Using the latest Quick and Nimble was pretty much the only code change required. We no longer need a framework for Result (even though this is was a good one). It's included in the standard library now, so the only thing we needed was an extension to add value and error to keep the tests happy (and anyone who was depending on those in their code). * Adjust from feedback. Needed to ignore a new file and I was incorrectly creating a new decoder in my fix (not sure how this worked in my tests like this). * Removing the need for Result. Now that Swift 5 provides this, we don't need it. * Eliminate Result extension. This caused the compiler to crash initially because there's so much type inferrence going on in the tests that it couldn't even report errors. I think I got it worked out to keep the intent behind the test without having the `value` and `error` fields.
1 parent 2dcbe67 commit ea24036

28 files changed

+84
-112
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ Carthage/Build
3535
.idea/
3636
*.iml
3737

38-
Argo.framework.zip

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "Carthage/Checkouts/Result"]
2-
path = Carthage/Checkouts/Result
3-
url = https://github.com/antitypical/Result.git
41
[submodule "Carthage/Checkouts/Nimble"]
52
path = Carthage/Checkouts/Nimble
63
url = https://github.com/Quick/Nimble.git

Cartfile

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
github "antitypical/Result" ~> 4.0

Cartfile.private

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "Quick/Quick" ~> 1.3
2-
github "Quick/Nimble" ~> 7.0
1+
github "Quick/Quick" ~> 2.0
2+
github "Quick/Nimble" ~> 8.0

Cartfile.resolved

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
github "Quick/Nimble" "v7.3.1"
2-
github "Quick/Quick" "v1.3.2"
3-
github "antitypical/Result" "4.0.0"
1+
github "Quick/Nimble" "v8.0.1"
2+
github "Quick/Quick" "v2.1.0"

Carthage/Checkouts/Nimble

Submodule Nimble updated 97 files

Carthage/Checkouts/Quick

Submodule Quick updated 68 files

Carthage/Checkouts/Result

-1
This file was deleted.

Source/Models/APIClient.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Result
32

43
public struct APIClient {
54
fileprivate let requestPerformer: RequestPerformer

Source/Models/NetworkRequestPerformer.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Result
32

43
public struct NetworkRequestPerformer: RequestPerformer {
54
fileprivate let session: URLSession

Source/Protocols/Client.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Result
32

43
public protocol Client {
54
@discardableResult

Source/Protocols/Request.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Result
32

43
public typealias EmptyResponse = Void
54

Source/Protocols/RequestPerformer.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Result
32

43
public protocol RequestPerformer {
54
@discardableResult

Swish.xcodeproj/project.pbxproj

+22-50
Large diffs are not rendered by default.

Swish.xcodeproj/xcshareddata/xcschemes/Swish-Mac.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Swish.xcodeproj/xcshareddata/xcschemes/Swish-iOS.xcscheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
codeCoverageEnabled = "YES"
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference

Swish.xcodeproj/xcshareddata/xcschemes/Swish-tvOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Swish.xcodeproj/xcshareddata/xcschemes/Swish-watchOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Swish.xcworkspace/contents.xcworkspacedata

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

SwishExamples.playground/Contents.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import PlaygroundSupport
22
import Swish
3-
import Result
43

54
PlaygroundPage.current.needsIndefiniteExecution = true
65

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Tests/Fakes/FakeRequest.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import Swish
3-
import Result
43

54
struct FakeRequest: Request {
65
typealias ResponseObject = String

Tests/Fakes/FakeRequestPerformer.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import Swish
3-
import Result
43

54
enum ResponseData {
65
case data(Data)

Tests/Helpers/NimbleMatchers.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Nimble
2-
import Result
32

43
public func beVoid() -> MatcherFunc<Void> {
54
return MatcherFunc { actualExpression, failureMessage in

Tests/Tests/APIClientSpec.swift

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Swish
22
import Quick
33
import Nimble
4-
import Result
54

65
class APIClientSpec: QuickSpec {
76
override func spec() {
@@ -32,8 +31,8 @@ class APIClientSpec: QuickSpec {
3231
var result: Result<String, SwishError>?
3332

3433
client.perform(request) { result = $0 }
35-
36-
expect(result?.value).toEventually(equal("hello world"))
34+
35+
expect { try result?.get() }.toEventually(equal("hello world"))
3736
}
3837
}
3938

@@ -45,10 +44,12 @@ class APIClientSpec: QuickSpec {
4544
)
4645

4746
let client = APIClient(requestPerformer: performer)
48-
var error: Error?
47+
var error: SwishError?
4948

50-
client.perform(request) {
51-
error = $0.error
49+
client.perform(request) { result in
50+
if case let .failure(resultError) = result {
51+
error = resultError
52+
}
5253
}
5354

5455
expect(error).toEventually(matchError(SwishError.self))
@@ -66,8 +67,8 @@ class APIClientSpec: QuickSpec {
6667
var result: Result<EmptyResponse, SwishError>?
6768

6869
client.perform(request) { result = $0 }
69-
70-
expect(result?.value).toEventually(beVoid())
70+
71+
expect { try result?.get() }.toEventually(beVoid())
7172
}
7273
}
7374

@@ -82,8 +83,8 @@ class APIClientSpec: QuickSpec {
8283
var result: Result<EmptyResponse, SwishError>?
8384

8485
client.perform(request) { result = $0 }
85-
86-
expect(result?.value).toEventually(beVoid())
86+
87+
expect { try result?.get() }.toEventually(beVoid())
8788
}
8889
}
8990
}
@@ -119,13 +120,13 @@ class APIClientSpec: QuickSpec {
119120
)
120121

121122
let client = APIClient(requestPerformer: performer)
122-
var error: SwishError?
123-
123+
var result: Result<String, SwishError>?
124+
124125
client.perform(request) {
125-
error = $0.error
126+
result = $0
126127
}
127-
128-
expect(error).toEventually(matchError(SwishError.serverError(code: expectedCode, data: performer.data)))
128+
129+
expect { try result?.get() }.toEventually(throwError(SwishError.serverError(code: expectedCode, data: performer.data)))
129130
}
130131
}
131132

@@ -140,13 +141,13 @@ class APIClientSpec: QuickSpec {
140141
)
141142

142143
let client = APIClient(requestPerformer: performer)
143-
var error: SwishError?
144+
var result: Result<String, SwishError>?
144145

145146
client.perform(request) {
146-
error = $0.error
147+
result = $0
147148
}
148149

149-
expect(error).toEventually(matchError(SwishError.serverError(code: expectedCode, data: performer.data)))
150+
expect { try result?.get() }.toEventually(throwError(SwishError.serverError(code: expectedCode, data: performer.data)))
150151
}
151152
}
152153

@@ -161,13 +162,13 @@ class APIClientSpec: QuickSpec {
161162
)
162163

163164
let client = APIClient(requestPerformer: performer)
164-
var error: SwishError?
165+
var result: Result<String, SwishError>?
165166

166167
client.perform(request) {
167-
error = $0.error
168+
result = $0
168169
}
169-
170-
expect(error).toEventually(matchError(SwishError.serverError(code: expectedCode, data: performer.data)))
170+
171+
expect { try result?.get() }.toEventually(throwError(SwishError.serverError(code: expectedCode, data: performer.data)))
171172
}
172173
}
173174

@@ -182,13 +183,13 @@ class APIClientSpec: QuickSpec {
182183
)
183184

184185
let client = APIClient(requestPerformer: performer)
185-
var error: SwishError?
186-
186+
var result: Result<String, SwishError>?
187+
187188
client.perform(request) {
188-
error = $0.error
189+
result = $0
189190
}
190-
191-
expect(error).toEventually(matchError(SwishError.serverError(code: expectedCode, data: performer.data)))
191+
192+
expect { try result?.get() }.toEventually(throwError(SwishError.serverError(code: expectedCode, data: performer.data)))
192193
}
193194
}
194195

Tests/Tests/NetworkRequestPerformerSpec.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Swish
22
import Quick
33
import Nimble
4-
import Result
54

65
func exampleRequest() -> URLRequest {
76
return URLRequest(url: URL(string: "https://example.com")!)
@@ -33,13 +32,14 @@ class RequestPerformerSpec: QuickSpec {
3332
context("when the request didn't produce an error") {
3433
it("returns a Result with the HTTPResponse") {
3534
let fakeSession = FakeSession(data: fakeData(), response: fakeResponse(200))
36-
var returnedCode: Int = 0
35+
var returnedCode: Int?
3736
var returnedData: Data?
3837

3938
let performer = NetworkRequestPerformer(session: fakeSession)
4039
performer.perform(exampleRequest()) { result in
41-
returnedCode = result.value!.code
42-
returnedData = result.value!.data
40+
let value = try? result.get()
41+
returnedCode = value?.code
42+
returnedData = value?.data
4343
}
4444

4545
expect(returnedCode).to(equal(200))
@@ -55,7 +55,9 @@ class RequestPerformerSpec: QuickSpec {
5555

5656
let performer = NetworkRequestPerformer(session: fakeSession)
5757
performer.perform(exampleRequest()) { result in
58-
returnedError = result.error
58+
if case .failure(let error) = result {
59+
returnedError = error
60+
}
5961
}
6062

6163
expect(returnedError).to(matchError(SwishError.urlSessionError(error, response: nil)))

Tests/Tests/RequestSpec.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Swish
22
import Quick
33
import Nimble
4-
import Result
54

65
struct User: Decodable {
76
let name: String

0 commit comments

Comments
 (0)