Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Commit f0d4b89

Browse files
committed
More Hashable models using Swift 4.1
1 parent 97cfceb commit f0d4b89

File tree

9 files changed

+21
-58
lines changed

9 files changed

+21
-58
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.1

Core/NetAuthorization.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
import Foundation
1010

11-
public enum NetAuthorization {
11+
public enum NetAuthorization: Hashable {
1212
case none, basic(user: String, password: String), bearer(token: String), custom(String)
1313
}
1414

15-
extension NetAuthorization: Equatable {}
16-
1715
extension NetAuthorization: RawRepresentable {
1816

1917
private struct StringValue {

Core/NetCacheControl.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
import Foundation
1010

11-
public enum NetCacheControl {
11+
public enum NetCacheControl: Equatable {
1212
case maxAge(TimeInterval), maxStale(TimeInterval?), minFresh(TimeInterval), noCache, noStore, noTransform, onlyIfCached, custom(String)
1313
}
1414

15-
extension NetCacheControl: Equatable {}
16-
1715
extension NetCacheControl: RawRepresentable {
1816

1917
private struct StringValue {

Core/NetContentType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public enum NetContentType {
11+
public enum NetContentType: Hashable {
1212
case aac, avi, bin, bmp, csv, form, formURL, gif, html, ico, ics, jpeg, js, json, mpeg, mpkg, ogx, pdf, pkcs7, plist, png, rar, rtf, svg, tar, tiff, ttf, txt, wav, weba, webm, webp, wildcard, xhtml, xml, zip, custom(String)
1313
}
1414

Core/NetMultipartFormData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class NetMultipartFormData {
2121
}
2222

2323
struct BoundaryGenerator {
24-
enum BoundaryType {
24+
enum BoundaryType: Hashable {
2525
case initial, encapsulated, final
2626
}
2727

Core/NetReachability.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import SystemConfiguration
1111

1212
public class NetReachability {
1313

14-
public enum Connection {
14+
public enum Connection: Hashable {
1515
case ethernetOrWiFi, wwan
1616
}
1717

18-
public enum Status {
18+
public enum Status: Hashable {
1919
case unknown, unreachable, reachable(Connection)
2020
}
2121

@@ -146,23 +146,6 @@ public class NetReachability {
146146

147147
}
148148

149-
extension NetReachability.Status: Equatable {
150-
151-
public static func ==(lhs: NetReachability.Status, rhs: NetReachability.Status) -> Bool {
152-
switch (lhs, rhs) {
153-
case (.unknown, .unknown):
154-
return true
155-
case (.unreachable, .unreachable):
156-
return true
157-
case let (.reachable(lhsConnectionType), .reachable(rhsConnectionType)):
158-
return lhsConnectionType == rhsConnectionType
159-
default:
160-
return false
161-
}
162-
}
163-
164-
}
165-
166149
extension NetReachability.Status: CustomStringConvertible {
167150

168151
public var description: String {

Core/NetRequest.swift

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public struct NetRequest {
11+
public struct NetRequest: Hashable {
1212

1313
public typealias NetContentLength = UInt64
1414

@@ -66,6 +66,10 @@ public struct NetRequest {
6666

6767
public let authorization: NetAuthorization
6868

69+
public var hashValue: Int {
70+
return url.hashValue + httpMethod.hashValue
71+
}
72+
6973
}
7074

7175
extension NetRequest {
@@ -165,19 +169,3 @@ extension NetRequest: CustomDebugStringConvertible {
165169
}
166170

167171
}
168-
169-
extension NetRequest: Hashable {
170-
171-
public var hashValue: Int {
172-
return url.hashValue + httpMethod.hashValue
173-
}
174-
175-
}
176-
177-
extension NetRequest: Equatable {
178-
179-
public static func ==(lhs: NetRequest, rhs: NetRequest) -> Bool {
180-
return lhs.url == rhs.url && lhs.httpMethod == rhs.httpMethod
181-
}
182-
183-
}

Core/NetResponse.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public struct NetResponse {
11+
public struct NetResponse: Equatable {
1212

1313
public let url: URL?
1414

@@ -32,6 +32,13 @@ public struct NetResponse {
3232

3333
let responseObject: Any?
3434

35+
public static func ==(lhs: NetResponse, rhs: NetResponse) -> Bool {
36+
guard lhs.url != nil && rhs.url != nil else {
37+
return false
38+
}
39+
return lhs.url == rhs.url
40+
}
41+
3542
}
3643

3744
extension NetResponse {
@@ -81,17 +88,6 @@ extension NetResponse {
8188

8289
}
8390

84-
extension NetResponse: Equatable {
85-
86-
public static func ==(lhs: NetResponse, rhs: NetResponse) -> Bool {
87-
guard lhs.url != nil && rhs.url != nil else {
88-
return false
89-
}
90-
return lhs.url == rhs.url
91-
}
92-
93-
}
94-
9591
extension NetResponse: CustomStringConvertible {
9692

9793
public var description: String {

Stub/NetStub.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open class NetStub: Net {
1313
case response(NetResponse), error(NetError)
1414
}
1515

16-
public enum AsyncBehavior {
16+
public enum AsyncBehavior: Equatable {
1717
case immediate(DispatchQueue?), delayed(DispatchQueue?, DispatchTimeInterval)
1818
}
1919

0 commit comments

Comments
 (0)