Skip to content

Commit

Permalink
Swift 5!!! (Alamofire#2771)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cnoon authored and jshier committed Mar 27, 2019
1 parent 0351aeb commit 050f4e0
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 37 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode10.1
osx_image: xcode10.2
branches:
only:
- master
Expand All @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions Alamofire.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 9 additions & 6 deletions Alamofire.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 1010;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = Alamofire;
TargetAttributes = {
4CCB207C1D45563900C64D5B = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 */;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 3 additions & 2 deletions Example/iOS Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source "https://rubygems.org"

gem "cocoapods", "~> 1.6.0.beta.2"
gem "cocoapods", "~> 1.6"
gem "xcpretty"
gem "jazzy"
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -98,7 +98,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.6.0.beta.2)
cocoapods (~> 1.6)
jazzy
xcpretty

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ let package = Package(
name: "Alamofire",
path: "Source")
],
swiftLanguageVersions: [.v4]
swiftLanguageVersions: [.v5]
)
2 changes: 1 addition & 1 deletion Source/ServerTrustEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
25 changes: 16 additions & 9 deletions Tests/ParameterEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions Tests/SessionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 050f4e0

Please sign in to comment.