Browse Source

Swift 5!!! (#2771)

* Updated Xcode project, source code, SPM package, and podspec to Swift 5

* Fixed up test suite failures due to behavioral changes in Swift 5

* Updated Travis-CI yml file to build against Xcode 10.2
Christian Noon 6 years ago
parent
commit
050f4e0311

+ 0 - 1
.swift-version

@@ -1 +0,0 @@
-4.2

+ 4 - 4
.travis.yml

@@ -1,5 +1,5 @@
 os: osx
-osx_image: xcode10.1
+osx_image: xcode10.2
 branches:
   only:
     - master
@@ -15,15 +15,15 @@ env:
   - WATCHOS_FRAMEWORK_SCHEME="Alamofire watchOS"
   - EXAMPLE_SCHEME="iOS Example"
   matrix:
-    - DESTINATION="OS=5.1,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
+    - DESTINATION="OS=5.2,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
     - DESTINATION="OS=4.2,name=Apple Watch Series 3 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
     - DESTINATION="OS=3.2,name=Apple Watch Series 2 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
 
-    - DESTINATION="OS=12.1,name=iPhone XS"       SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
+    - DESTINATION="OS=12.2,name=iPhone XS"       SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
     - DESTINATION="OS=11.4,name=iPhone X"        SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
     - DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
 
-    - DESTINATION="OS=12.1,name=Apple TV 4K"    SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
+    - DESTINATION="OS=12.2,name=Apple TV 4K"    SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
     - DESTINATION="OS=11.4,name=Apple TV 4K"    SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
     - DESTINATION="OS=10.2,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
 

+ 2 - 0
Alamofire.podspec

@@ -14,6 +14,8 @@ Pod::Spec.new do |s|
   s.tvos.deployment_target = '10.0'
   s.watchos.deployment_target = '3.0'
 
+  s.swift_version = '5.0'
+
   s.source_files = 'Source/*.swift'
   
   s.frameworks = 'CFNetwork'

+ 9 - 6
Alamofire.xcodeproj/project.pbxproj

@@ -1071,7 +1071,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 0700;
-				LastUpgradeCheck = 1010;
+				LastUpgradeCheck = 1020;
 				ORGANIZATIONNAME = Alamofire;
 				TargetAttributes = {
 					4CCB207C1D45563900C64D5B = {
@@ -1099,12 +1099,12 @@
 					};
 					F8111E3219A95C8B0040E7D1 = {
 						CreatedOnToolsVersion = 6.0;
-						LastSwiftMigration = 0900;
+						LastSwiftMigration = 1020;
 						ProvisioningStyle = Manual;
 					};
 					F8111E3D19A95C8B0040E7D1 = {
 						CreatedOnToolsVersion = 6.0;
-						LastSwiftMigration = 0900;
+						LastSwiftMigration = 1020;
 						ProvisioningStyle = Manual;
 					};
 					F829C6B11A7A94F100A2CD59 = {
@@ -1116,10 +1116,11 @@
 			};
 			buildConfigurationList = F8111E2D19A95C8B0040E7D1 /* Build configuration list for PBXProject "Alamofire" */;
 			compatibilityVersion = "Xcode 3.2";
-			developmentRegion = English;
+			developmentRegion = en;
 			hasScannedForEncodings = 0;
 			knownRegions = (
 				en,
+				Base,
 			);
 			mainGroup = F8111E2919A95C8B0040E7D1;
 			productRefGroup = F8111E3419A95C8B0040E7D1 /* Products */;
@@ -1718,6 +1719,7 @@
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				APPLICATION_EXTENSION_API_ONLY = YES;
+				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
@@ -1776,7 +1778,7 @@
 				PRODUCT_NAME = Alamofire;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_SWIFT3_OBJC_INFERENCE = Off;
-				SWIFT_VERSION = 4.2;
+				SWIFT_VERSION = 5.0;
 				TVOS_DEPLOYMENT_TARGET = 10.0;
 				VERSIONING_SYSTEM = "apple-generic";
 				WATCHOS_DEPLOYMENT_TARGET = 3.0;
@@ -1788,6 +1790,7 @@
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				APPLICATION_EXTENSION_API_ONLY = YES;
+				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
@@ -1838,7 +1841,7 @@
 				PRODUCT_NAME = Alamofire;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
 				SWIFT_SWIFT3_OBJC_INFERENCE = Off;
-				SWIFT_VERSION = 4.2;
+				SWIFT_VERSION = 5.0;
 				TVOS_DEPLOYMENT_TARGET = 10.0;
 				VALIDATE_PRODUCT = YES;
 				VERSIONING_SYSTEM = "apple-generic";

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

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

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

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1010"
+   LastUpgradeVersion = "1020"
    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 = "1010"
+   LastUpgradeVersion = "1020"
    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 = "1010"
+   LastUpgradeVersion = "1020"
    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 = "1010"
+   LastUpgradeVersion = "1020"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 3 - 2
Example/iOS Example.xcodeproj/project.pbxproj

@@ -219,6 +219,7 @@
 			developmentRegion = English;
 			hasScannedForEncodings = 0;
 			knownRegions = (
+				English,
 				en,
 				Base,
 			);
@@ -386,7 +387,7 @@
 				SDKROOT = iphoneos;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_SWIFT3_OBJC_INFERENCE = Off;
-				SWIFT_VERSION = 4.2;
+				SWIFT_VERSION = 5.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TVOS_DEPLOYMENT_TARGET = 10.0;
 				WATCHOS_DEPLOYMENT_TARGET = 3.0;
@@ -436,7 +437,7 @@
 				SDKROOT = iphoneos;
 				SWIFT_COMPILATION_MODE = wholemodule;
 				SWIFT_SWIFT3_OBJC_INFERENCE = Off;
-				SWIFT_VERSION = 4.2;
+				SWIFT_VERSION = 5.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TVOS_DEPLOYMENT_TARGET = 10.0;
 				VALIDATE_PRODUCT = 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 = "1010"
+   LastUpgradeVersion = "1020"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Gemfile

@@ -1,5 +1,5 @@
 source "https://rubygems.org"
 
-gem "cocoapods", "~> 1.6.0.beta.2"
+gem "cocoapods", "~> 1.6"
 gem "xcpretty"
 gem "jazzy"

+ 4 - 4
Gemfile.lock

@@ -2,7 +2,7 @@ GEM
   remote: https://rubygems.org/
   specs:
     CFPropertyList (3.0.0)
-    activesupport (4.2.11)
+    activesupport (4.2.11.1)
       i18n (~> 0.7)
       minitest (~> 5.1)
       thread_safe (~> 0.3, >= 0.3.4)
@@ -32,7 +32,7 @@ GEM
       activesupport (>= 4.0.2, < 6)
       fuzzy_match (~> 2.0.4)
       nap (~> 1.0)
-    cocoapods-deintegrate (1.0.3)
+    cocoapods-deintegrate (1.0.4)
     cocoapods-downloader (1.2.2)
     cocoapods-plugins (1.0.0)
       nap
@@ -43,7 +43,7 @@ GEM
       netrc (~> 0.11)
     cocoapods-try (1.1.0)
     colored2 (3.1.2)
-    concurrent-ruby (1.1.4)
+    concurrent-ruby (1.1.5)
     escape (0.0.4)
     ffi (1.10.0)
     fourflusher (2.2.0)
@@ -98,7 +98,7 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  cocoapods (~> 1.6.0.beta.2)
+  cocoapods (~> 1.6)
   jazzy
   xcpretty
 

+ 1 - 1
Package.swift

@@ -43,5 +43,5 @@ let package = Package(
             name: "Alamofire",
             path: "Source")
     ],
-    swiftLanguageVersions: [.v4]
+    swiftLanguageVersions: [.v5]
 )

+ 1 - 1
Source/ServerTrustEvaluation.swift

@@ -519,7 +519,7 @@ public extension AlamofireExtension where ExtendedType == Array<SecCertificate>
     }
 
     /// All public `SecKey` values for the contained `SecCertificate`s.
-    public var publicKeys: [SecKey] {
+    var publicKeys: [SecKey] {
         return type.compactMap { $0.af.publicKey }
     }
 }

+ 16 - 9
Tests/ParameterEncoderTests.swift

@@ -370,7 +370,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
 
         // Then
         let expected = "four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&three=1&one=one&two=2&five%5Ba%5D=a&six%5Ba%5D%5Bb%5D=b&seven%5Ba%5D=a"
-        XCTAssertEqual(result.value, expected)
+        XCTAssertQueryEqual(result.value, expected)
     }
 
     func testThatManuallyEncodableStructCanBeEncoded() {
@@ -383,7 +383,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
 
         // Then
         let expected = "root%5B%5D%5B%5D=1&root%5B%5D%5B%5D=2&root%5B%5D%5B%5D=3&root%5B%5D%5Ba%5D%5Bstring%5D=string&root%5B%5D%5B%5D%5B%5D=1&root%5B%5D%5B%5D%5B%5D=2&root%5B%5D%5B%5D%5B%5D=3"
-        XCTAssertEqual(result.value, expected)
+        XCTAssertQueryEqual(result.value, expected)
     }
 
     func testThatEncodableClassWithNoInheritanceCanBeEncoded() {
@@ -395,7 +395,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
         let result = Result<String> { try encoder.encode(parameters) }
 
         // Then
-        XCTAssertEqual(result.value, "two=2&one=one&three=1")
+        XCTAssertQueryEqual(result.value, "two=2&one=one&three=1")
     }
 
     func testThatEncodableSubclassCanBeEncoded() {
@@ -408,7 +408,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
 
         // Then
         let expected = "four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&two=2&five%5Ba%5D=a&five%5Bb%5D=b&three=1&one=one"
-        XCTAssertEqual(result.value, expected)
+        XCTAssertQueryEqual(result.value, expected)
     }
 
     func testThatManuallyEncodableSubclassCanBeEncoded() {
@@ -421,7 +421,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
 
         // Then
         let expected = "five%5Ba%5D=a&five%5Bb%5D=b&four%5Bfour%5D=one&four%5Bfive%5D=2"
-        XCTAssertEqual(result.value, expected)
+        XCTAssertQueryEqual(result.value, expected)
     }
 
     func testThatARootArrayCannotBeEncoded() {
@@ -481,7 +481,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
         let result = Result<String> { try encoder.encode(parameters) }
 
         // Then
-        XCTAssertEqual(result.value, "array=1&array=2")
+        XCTAssertQueryEqual(result.value, "array=1&array=2")
     }
 
     func testThatSpacesCanBeEncodedAsPluses() {
@@ -521,7 +521,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
         let result = Result<String> { try encoder.encode(parameters) }
 
         // Then
-        XCTAssertEqual(result.value,
+        XCTAssertQueryEqual(result.value,
                        "uppercase=ABCDEFGHIJKLMNOPQRSTUVWXYZ&numbers=0123456789&lowercase=abcdefghijklmnopqrstuvwxyz")
     }
 
@@ -560,7 +560,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
         let result = Result<String> { try encoder.encode(parameters) }
 
         // Then
-        XCTAssertEqual(result.value, "foobar=bazqux&foo%26bar=baz%26qux")
+        XCTAssertQueryEqual(result.value, "foobar=bazqux&foo%26bar=baz%26qux")
     }
 
     func testThatQuestionMarksInKeysAndValuesAreNotPercentEscaped() {
@@ -643,7 +643,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase {
             "french=fran%C3%A7ais",
             "emoji=%F0%9F%98%83"
         ].joined(separator: "&")
-        XCTAssertEqual(result.value, expectedParameterValues)
+        XCTAssertQueryEqual(result.value, expectedParameterValues)
     }
 
     func testStringWithThousandsOfChineseCharactersIsPercentEscaped() {
@@ -780,3 +780,10 @@ private struct FailingOptionalStruct: Encodable {
         }
     }
 }
+
+private func XCTAssertQueryEqual(_ query1: String?, _ query2: String?) {
+    let items1 = query1?.split(separator: "&").sorted()
+    let items2 = query2?.split(separator: "&").sorted()
+
+    XCTAssertEqual(items1, items2)
+}

+ 3 - 2
Tests/SessionTests.swift

@@ -306,8 +306,9 @@ class SessionTestCase: BaseTestCase {
             return "Alamofire/\(build)"
         }()
 
-        let expectedUserAgent = "Unknown/Unknown (Unknown; build:Unknown; \(osNameVersion)) \(alamofireVersion)"
-        XCTAssertEqual(userAgent, expectedUserAgent)
+        XCTAssertTrue(userAgent?.contains(alamofireVersion) == true)
+        XCTAssertTrue(userAgent?.contains(osNameVersion) == true)
+        XCTAssertTrue(userAgent?.contains("Unknown/Unknown") == true)
     }
 
     // MARK: Tests - Supported Accept-Encodings