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

Restore Swift 5 Support #3077

Merged
merged 2 commits into from Feb 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .swiftformat
Expand Up @@ -4,6 +4,7 @@
--swiftversion 5

# rules
--enable isEmpty
--disable andOperator

# format options
Expand All @@ -15,11 +16,12 @@
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--ifdef outdent
--ifdef no-indent
--importgrouping testable-top
--operatorfunc no-space
--nospaceoperators ..<, ...
--selfrequired validate
--stripunusedargs closure-only
--wraparguments after-first
--wrapcollections after-first
--wrapcollections after-first
--wrapparameters after-first
7 changes: 0 additions & 7 deletions Source/AlamofireExtended.swift
Expand Up @@ -23,7 +23,6 @@
//

/// Type that acts as a generic extension point for all `AlamofireExtended` types.
@dynamicMemberLookup
public struct AlamofireExtension<ExtendedType> {
/// Stores the type or meta-type of any extended type.
public private(set) var type: ExtendedType
Expand All @@ -34,12 +33,6 @@ public struct AlamofireExtension<ExtendedType> {
public init(_ type: ExtendedType) {
self.type = type
}

/// Get and set properties through a `WritableKeyPath` subscript for `@dynamicMemberLookup`.
public subscript<Property>(dynamicMember keyPath: WritableKeyPath<ExtendedType, Property>) -> Property {
get { type[keyPath: keyPath] }
set { type[keyPath: keyPath] = newValue }
}
}

/// Protocol describing the `af` extension points for Alamofire extended types.
Expand Down
6 changes: 3 additions & 3 deletions Source/NetworkReachabilityManager.swift
Expand Up @@ -240,11 +240,11 @@ extension SCNetworkReachabilityFlags {
var canConnectWithoutUserInteraction: Bool { return canConnectAutomatically && !contains(.interventionRequired) }
var isActuallyReachable: Bool { return isReachable && (!isConnectionRequired || canConnectWithoutUserInteraction) }
var isCellular: Bool {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS)
return contains(.isWWAN)
#else
#else
return false
#endif
#endif
}

/// Human readable `String` for all states, to help with debugging.
Expand Down
16 changes: 8 additions & 8 deletions Source/ServerTrustEvaluation.swift
Expand Up @@ -73,9 +73,9 @@ open class ServerTrustManager {

/// A protocol describing the API used to evaluate server trusts.
public protocol ServerTrustEvaluating {
#if os(Linux)
// Implement this once Linux has API for evaluating server trusts.
#else
#if os(Linux)
// Implement this once Linux has API for evaluating server trusts.
#else
/// Evaluates the given `SecTrust` value for the given `host`.
///
/// - Parameters:
Expand All @@ -84,7 +84,7 @@ public protocol ServerTrustEvaluating {
///
/// - Returns: A `Bool` indicating whether the evaluator considers the `SecTrust` value valid for `host`.
func evaluate(_ trust: SecTrust, forHost host: String) throws
#endif
#endif
}

// MARK: - Server Trust Evaluators
Expand Down Expand Up @@ -345,9 +345,9 @@ public final class DisabledEvaluator: ServerTrustEvaluating {
// MARK: - Extensions

public extension Array where Element == ServerTrustEvaluating {
#if os(Linux)
// Add this same convenience method for Linux.
#else
#if os(Linux)
// Add this same convenience method for Linux.
#else
/// Evaluates the given `SecTrust` value for the given `host`.
///
/// - Parameters:
Expand All @@ -360,7 +360,7 @@ public extension Array where Element == ServerTrustEvaluating {
try evaluator.evaluate(trust, forHost: host)
}
}
#endif
#endif
}

extension Bundle: AlamofireExtended {}
Expand Down
2 changes: 1 addition & 1 deletion Source/Validation.swift
Expand Up @@ -97,7 +97,7 @@ extension Request {
data: Data?)
-> ValidationResult
where S.Iterator.Element == String {
guard let data = data, data.count > 0 else { return .success(Void()) }
guard let data = data, !data.isEmpty else { return .success(Void()) }

guard
let responseContentType = response.mimeType,
Expand Down
4 changes: 2 additions & 2 deletions Tests/NetworkReachabilityManagerTests.swift
Expand Up @@ -257,7 +257,7 @@ final class NetworkReachabilityManagerTestCase: BaseTestCase {
XCTAssertEqual(status, .reachable(.ethernetOrWiFi))
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS)
func testThatStatusIsReachableOnCellularStatusWhenIsWWAN() {
// Given
let flags: SCNetworkReachabilityFlags = [.reachable, .isWWAN]
Expand All @@ -279,5 +279,5 @@ final class NetworkReachabilityManagerTestCase: BaseTestCase {
// Then
XCTAssertEqual(status, .notReachable)
}
#endif
#endif
}
10 changes: 5 additions & 5 deletions Tests/ServerTrustEvaluatorTests.swift
Expand Up @@ -1396,18 +1396,18 @@ class ServerTrustPolicyCertificatesInBundleTestCase: ServerTrustPolicyTestCase {
// When
let certificates = Bundle(for: ServerTrustPolicyCertificatesInBundleTestCase.self).af.certificates

// Then
// Expectation: 19 well-formed certificates in the test bundle plus 4 invalid certificates.
#if os(macOS)
// Then
// Expectation: 19 well-formed certificates in the test bundle plus 4 invalid certificates.
#if os(macOS)
// For some reason, macOS is allowing all certificates to be considered valid. Need to file a
// rdar demonstrating this behavior.
if #available(macOS 10.12, *) {
XCTAssertEqual(certificates.count, 19, "Expected 19 well-formed certificates")
} else {
XCTAssertEqual(certificates.count, 23, "Expected 23 well-formed certificates")
}
#else
#else
XCTAssertEqual(certificates.count, 19, "Expected 19 well-formed certificates")
#endif
#endif
}
}
18 changes: 9 additions & 9 deletions Tests/SessionTests.swift
Expand Up @@ -274,19 +274,19 @@ final class SessionTestCase: BaseTestCase {
let versionString = "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"

let osName: String = {
#if os(iOS)
#if os(iOS)
return "iOS"
#elseif os(watchOS)
#elseif os(watchOS)
return "watchOS"
#elseif os(tvOS)
#elseif os(tvOS)
return "tvOS"
#elseif os(macOS)
#elseif os(macOS)
return "macOS"
#elseif os(Linux)
#elseif os(Linux)
return "Linux"
#else
#else
return "Unknown"
#endif
#endif
}()

return "\(osName) \(versionString)"
Expand Down Expand Up @@ -1683,12 +1683,12 @@ final class SessionConfigurationHeadersTestCase: BaseTestCase {
executeAuthorizationHeaderTest(for: .ephemeral)
}

#if os(macOS)
#if os(macOS)
func disabled_testThatBackgroundConfigurationHeadersAreSentWithRequest() {
// Given, When, Then
executeAuthorizationHeaderTest(for: .background)
}
#endif
#endif

private func executeAuthorizationHeaderTest(for type: ConfigurationType) {
// Given
Expand Down
4 changes: 2 additions & 2 deletions Tests/UploadTests.swift
Expand Up @@ -515,7 +515,7 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
}
}

#if os(macOS)
#if os(macOS)
func disabled_testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
// Given
let manager: Session = {
Expand Down Expand Up @@ -564,7 +564,7 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
return
}
}
#endif
#endif

// MARK: Combined Test Execution

Expand Down