Browse Source

Make Alamofire build under Xcode 9 with Swift 3.2 and 4.

Jon Shier 8 years ago
parent
commit
0edade1183

+ 17 - 1
Alamofire.xcodeproj/project.pbxproj

@@ -900,7 +900,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 0700;
-				LastUpgradeCheck = 0820;
+				LastUpgradeCheck = 0900;
 				ORGANIZATIONNAME = Alamofire;
 				TargetAttributes = {
 					4CCB207C1D45563900C64D5B = {
@@ -1511,14 +1511,22 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
+				CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -1567,14 +1575,22 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
+				CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

+ 3 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire iOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"
@@ -40,6 +40,8 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      enableAddressSanitizer = "YES"
+      enableUBSanitizer = "YES"
       shouldUseLaunchSchemeArgsEnv = "YES">
       <Testables>
          <TestableReference

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire macOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire tvOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire watchOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Cleanup Whitespace.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 8 - 0
Alamofire.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>BuildSystemType</key>
+	<string>Latest</string>
+</dict>
+</plist>

+ 13 - 1
Example/iOS Example.xcodeproj/project.pbxproj

@@ -206,7 +206,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 0720;
-				LastUpgradeCheck = 0800;
+				LastUpgradeCheck = 0900;
 				ORGANIZATIONNAME = Alamofire;
 				TargetAttributes = {
 					F8111E0419A951050040E7D1 = {
@@ -344,14 +344,20 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -396,14 +402,20 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

+ 1 - 1
Example/iOS Example.xcodeproj/xcshareddata/xcschemes/iOS Example.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0820"
+   LastUpgradeVersion = "0900"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 4 - 1
Source/ParameterEncoding.swift

@@ -241,8 +241,11 @@ public struct URLEncoding: ParameterEncoding {
             let value = parameters[key]!
             components += queryComponents(fromKey: key, value: value)
         }
-
+        #if swift(>=4.0)
+        return components.map { "\($0.0)=\($0.1)" }.joined(separator: "&")
+        #else
         return components.map { "\($0)=\($1)" }.joined(separator: "&")
+        #endif
     }
 
     private func encodesParametersInURL(with method: HTTPMethod) -> Bool {

+ 9 - 1
Source/SessionManager.swift

@@ -58,11 +58,19 @@ open class SessionManager {
         let acceptEncoding: String = "gzip;q=1.0, compress;q=0.5"
 
         // Accept-Language HTTP Header; see https://tools.ietf.org/html/rfc7231#section-5.3.5
+        #if swift(>=4.0)
+            let acceptLanguage = Locale.preferredLanguages.prefix(6).enumerated().map { enumeratedLanguage in
+                let (index, languageCode) = enumeratedLanguage
+                let quality = 1.0 - (Double(index) * 0.1)
+            return "\(languageCode);q=\(quality)"
+        }.joined(separator: ", ")
+        #else
         let acceptLanguage = Locale.preferredLanguages.prefix(6).enumerated().map { index, languageCode in
             let quality = 1.0 - (Double(index) * 0.1)
             return "\(languageCode);q=\(quality)"
         }.joined(separator: ", ")
-
+        #endif
+        
         // User-Agent Header; see https://tools.ietf.org/html/rfc7231#section-5.5.3
         // Example: `iOS Example/1.0 (org.alamofire.iOS-Example; build:1; iOS 10.0.0) Alamofire/4.0.0`
         let userAgent: String = {

+ 2 - 2
Tests/RequestTests.swift

@@ -382,7 +382,7 @@ class RequestResponseTestCase: BaseTestCase {
 // MARK: -
 
 extension Request {
-    fileprivate func preValidate(operation: @escaping (Void) -> Void) -> Self {
+    fileprivate func preValidate(operation: @escaping () -> Void) -> Self {
         delegate.queue.addOperation {
             operation()
         }
@@ -390,7 +390,7 @@ extension Request {
         return self
     }
 
-    fileprivate func postValidate(operation: @escaping (Void) -> Void) -> Self {
+    fileprivate func postValidate(operation: @escaping () -> Void) -> Self {
         delegate.queue.addOperation {
             operation()
         }

+ 6 - 6
Tests/SessionManagerTests.swift

@@ -787,12 +787,12 @@ class SessionManagerConfigurationHeadersTestCase: BaseTestCase {
         // Given, When, Then
         executeAuthorizationHeaderTest(for: .ephemeral)
     }
-
-//    ⚠️ This test has been removed as a result of rdar://26870455 in Xcode 8 Seed 1
-//    func testThatBackgroundConfigurationHeadersAreSentWithRequest() {
-//        // Given, When, Then
-//        executeAuthorizationHeaderTest(for: .background)
-//    }
+    #if os(macOS)
+    func testThatBackgroundConfigurationHeadersAreSentWithRequest() {
+        // Given, When, Then
+        executeAuthorizationHeaderTest(for: .background)
+    }
+    #endif
 
     private func executeAuthorizationHeaderTest(for type: ConfigurationType) {
         // Given

+ 6 - 6
Tests/URLProtocolTests.swift

@@ -92,19 +92,19 @@ class ProxyURLProtocol: URLProtocol {
 
 // MARK: -
 
-extension ProxyURLProtocol: URLSessionDelegate {
+extension ProxyURLProtocol: URLSessionDataDelegate {
 
     // MARK: NSURLSessionDelegate
-
-    func URLSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceiveData data: Data) {
+    
+    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
         client?.urlProtocol(self, didLoad: data)
     }
-
-    func URLSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
+    
+    func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
         if let response = task.response {
             client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
         }
-
+        
         client?.urlProtocolDidFinishLoading(self)
     }
 }

+ 60 - 63
Tests/UploadTests.swift

@@ -532,70 +532,67 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
             XCTFail("Content-Type header value should not be nil")
         }
     }
+    
+    #if os(macOS)
+    func testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
+        // Given
+        let manager: SessionManager = {
+            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"
+            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)
 
-//    ⚠️ This test has been removed as a result of rdar://26870455 in Xcode 8 Seed 1
-//    func testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
-//        // Given
-//        let manager: SessionManager = {
-//            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"
-//            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)
-//
-//            return SessionManager(configuration: configuration, serverTrustPolicyManager: nil)
-//        }()
-//
-//        let urlString = "https://httpbin.org/post"
-//        let french = "français".data(using: .utf8, allowLossyConversion: false)!
-//        let japanese = "日本語".data(using: .utf8, allowLossyConversion: false)!
-//
-//        let expectation = self.expectation(description: "multipart form data upload should succeed")
-//
-//        var request: URLRequest?
-//        var response: HTTPURLResponse?
-//        var data: Data?
-//        var error: Error?
-//        var streamingFromDisk: Bool?
-//
-//        // When
-//        manager.upload(
-//            multipartFormData: { multipartFormData in
-//                multipartFormData.append(french, withName: "french")
-//                multipartFormData.append(japanese, withName: "japanese")
-//            },
-//            to: urlString,
-//            withMethod: .post,
-//            encodingCompletion: { result in
-//                switch result {
-//                case let .success(upload, uploadStreamingFromDisk, _):
-//                    streamingFromDisk = uploadStreamingFromDisk
-//
-//                    upload.response { responseRequest, responseResponse, responseData, responseError in
-//                        request = responseRequest
-//                        response = responseResponse
-//                        data = responseData
-//                        error = responseError
-//
-//                        expectation.fulfill()
-//                    }
-//                case .failure:
-//                    expectation.fulfill()
-//                }
-//            }
-//        )
-//
-//        waitForExpectations(timeout: timeout, handler: nil)
-//
-//        // Then
-//        XCTAssertNotNil(request, "request should not be nil")
-//        XCTAssertNotNil(response, "response should not be nil")
-//        XCTAssertNotNil(data, "data should not be nil")
-//        XCTAssertNil(error, "error should be nil")
-//
-//        if let streamingFromDisk = streamingFromDisk {
-//            XCTAssertTrue(streamingFromDisk, "streaming from disk should be true")
-//        } else {
-//            XCTFail("streaming from disk should not be nil")
-//        }
-//    }
+            return SessionManager(configuration: configuration, serverTrustPolicyManager: nil)
+        }()
+
+        let urlString = "https://httpbin.org/post"
+        let french = "français".data(using: .utf8, allowLossyConversion: false)!
+        let japanese = "日本語".data(using: .utf8, allowLossyConversion: false)!
+
+        let expectation = self.expectation(description: "multipart form data upload should succeed")
+
+        var request: URLRequest?
+        var response: HTTPURLResponse?
+        var data: Data?
+        var error: Error?
+        var streamingFromDisk: Bool?
+
+        // When
+        manager.upload(multipartFormData: { multipartFormData in
+            multipartFormData.append(french, withName: "french")
+            multipartFormData.append(japanese, withName: "japanese")
+        }, to: urlString,
+           encodingCompletion: { result in
+            switch result {
+            case let .success(upload, uploadStreamingFromDisk, _):
+                streamingFromDisk = uploadStreamingFromDisk
+                
+                upload.response { defaultResponse in
+                    request = defaultResponse.request
+                    response = defaultResponse.response
+                    data = defaultResponse.data
+                    error = defaultResponse.error
+                    
+                    expectation.fulfill()
+                }
+            case .failure:
+                expectation.fulfill()
+            }
+        })
+        
+        waitForExpectations(timeout: timeout, handler: nil)
+
+        // Then
+        XCTAssertNotNil(request, "request should not be nil")
+        XCTAssertNotNil(response, "response should not be nil")
+        XCTAssertNotNil(data, "data should not be nil")
+        XCTAssertNil(error, "error should be nil")
+
+        if let streamingFromDisk = streamingFromDisk {
+            XCTAssertTrue(streamingFromDisk, "streaming from disk should be true")
+        } else {
+            XCTFail("streaming from disk should not be nil")
+        }
+    }
+    #endif
 
     // MARK: Combined Test Execution