Skip to content

Commit

Permalink
Merge pull request #268 from chn-lyzhi/develop-Swift5
Browse files Browse the repository at this point in the history
Support Swift 5.0
  • Loading branch information
ikesyo authored Apr 12, 2019
2 parents f14b5eb + 5f4b96b commit 862a8f8
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 108 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
5.0
19 changes: 5 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,32 @@ env:
matrix:
include:
- &podspec
name: CocoaPods Lint
os: osx
language: objective-c
osx_image: xcode10.2
script:
- pod lib lint --allow-warnings
- &xcode
name: Xcode 10.2 / Swift 5.0
os: osx
language: objective-c
osx_image: xcode9.2
osx_image: xcode10.2
script:
- set -o pipefail
- xcodebuild build-for-testing test-without-building -workspace APIKit.xcworkspace -scheme APIKit -configuration Release ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -workspace APIKit.xcworkspace -scheme APIKit -configuration Release -sdk iphonesimulator -destination "name=iPhone 6s" ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -workspace APIKit.xcworkspace -scheme APIKit -configuration Release -sdk appletvsimulator -destination "name=Apple TV" ENABLE_TESTABILITY=YES | xcpretty -c
after_success:
- bash <(curl -s https://codecov.io/bash)
- <<: *xcode
osx_image: xcode9.4
- <<: *xcode
osx_image: xcode10.1
- <<: *xcode
osx_image: xcode10.2
- &swiftpm
name: SwiftPM / Darwin / Swift 5.0
os: osx
language: generic
osx_image: xcode9.2
osx_image: xcode10.2
script:
- swift build
- swift test
- <<: *swiftpm
osx_image: xcode9.4
- <<: *swiftpm
osx_image: xcode10.1
- <<: *swiftpm
osx_image: xcode10.2

notifications:
email: false
6 changes: 2 additions & 4 deletions APIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "APIKit"
s.version = "4.1.0"
s.version = "5.0.0"
s.summary = "Type-safe networking abstraction layer that associates request type with response type."
s.homepage = "https://github.com/ishkawa/APIKit"

Expand All @@ -23,7 +23,7 @@ Pod::Spec.new do |s|
:tag => "#{s.version}",
}

s.swift_version = "4.0"
s.swift_version = "5.0"

s.license = {
:type => "MIT",
Expand All @@ -34,6 +34,4 @@ Pod::Spec.new do |s|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE
}

s.dependency "Result", "~> 4.0"
end
18 changes: 6 additions & 12 deletions APIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
141F12201C1C9ABE0026D415 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD5115241B1FFBA900514240 /* Result.framework */; };
141F12311C1C9AC70026D415 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD5115241B1FFBA900514240 /* Result.framework */; };
141F12361C1C9AC70026D415 /* Result.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = CD5115241B1FFBA900514240 /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
7F698E501D9D680C00F1561D /* FormURLEncodedBodyParametersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E3C1D9D680C00F1561D /* FormURLEncodedBodyParametersTests.swift */; };
7F698E511D9D680C00F1561D /* JSONBodyParametersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E3D1D9D680C00F1561D /* JSONBodyParametersTests.swift */; };
7F698E521D9D680C00F1561D /* MultipartFormDataParametersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E3E1D9D680C00F1561D /* MultipartFormDataParametersTests.swift */; };
Expand Down Expand Up @@ -72,7 +69,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
141F12361C1C9AC70026D415 /* Result.framework in Copy Frameworks */,
);
name = "Copy Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -129,7 +125,6 @@
7F7048F21D9D8A1F003C99F6 /* URLEncodedSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = URLEncodedSerialization.swift; path = Sources/APIKit/Serializations/URLEncodedSerialization.swift; sourceTree = SOURCE_ROOT; };
7F8ECDFD1B6A799E00234E04 /* Demo.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Demo.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
7FA1690C1D9D8C80006C982B /* HTTPStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPStub.swift; sourceTree = "<group>"; };
CD5115241B1FFBA900514240 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Result.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECA831471DE4DDBF004EB1B5 /* ProtobufDataParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProtobufDataParser.swift; path = Sources/APIKit/DataParser/ProtobufDataParser.swift; sourceTree = SOURCE_ROOT; };
ECA831491DE4DEBE004EB1B5 /* ProtobufDataParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtobufDataParserTests.swift; sourceTree = "<group>"; };
ECA8314B1DE4E677004EB1B5 /* ProtobufBodyParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProtobufBodyParameters.swift; path = Sources/APIKit/BodyParameters/ProtobufBodyParameters.swift; sourceTree = SOURCE_ROOT; };
Expand All @@ -141,15 +136,13 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
141F12201C1C9ABE0026D415 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
141F12301C1C9AC70026D415 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
141F12311C1C9AC70026D415 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -308,7 +301,6 @@
children = (
7F7048C61D9D89BE003C99F6 /* APIKit.h */,
7F7048C91D9D89BE003C99F6 /* Info.plist */,
CD5115241B1FFBA900514240 /* Result.framework */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -402,7 +394,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Yosuke Ishikawa";
TargetAttributes = {
141F12161C1C9ABE0026D415 = {
Expand All @@ -415,7 +407,7 @@
};
buildConfigurationList = 7F45FCD71A94D02C006863BB /* Build configuration list for PBXProject "APIKit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -562,6 +554,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 141F12101C1C96820026D415 /* Debug.xcconfig */;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
Expand All @@ -575,14 +568,15 @@
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
7F45FCF21A94D02C006863BB /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 141F12111C1C96820026D415 /* Release.xcconfig */;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
Expand All @@ -594,7 +588,7 @@
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
GCC_NO_COMMON_BLOCKS = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion APIKit.xcodeproj/xcshareddata/xcschemes/APIKit.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
3 changes: 0 additions & 3 deletions APIKit.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cartfile

This file was deleted.

1 change: 0 additions & 1 deletion Cartfile.resolved

This file was deleted.

1 change: 0 additions & 1 deletion Carthage/Checkouts/Result
Submodule Result deleted from 8fc088
16 changes: 0 additions & 16 deletions Package.resolved

This file was deleted.

13 changes: 7 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// swift-tools-version:4.0
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "APIKit",
platforms: [
.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)
],
products: [
.library(name: "APIKit", targets: ["APIKit"]),
],
dependencies: [
.package(url: "https://github.com/antitypical/Result.git", from: "4.0.0"),
],
dependencies: [],
targets: [
.target(
name: "APIKit",
dependencies: ["Result"],
dependencies: [],
exclude: ["BodyParameters/AbstractInputStream.m"]
),
.testTarget(
name: "APIKitTests",
dependencies: ["APIKit"]
),
],
swiftLanguageVersions: [4]
swiftLanguageVersions: [.v5]
)
24 changes: 0 additions & 24 deletions [email protected]

This file was deleted.

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@ Session.send(request) { result in

## Requirements

- Swift 3.0 or later
- Swift 5.0 or later
- iOS 8.0 or later
- Mac OS 10.10 or later
- watchOS 2.0 or later
- tvOS 9.0 or later

If you use Swift 2.2 or 2.3, try [APIKit 2.0.5](https://github.com/ishkawa/APIKit/tree/2.0.5).

If you use Swift 4.2 or before, try [APIKit 4.1.0](https://github.com/ishkawa/APIKit/tree/4.1.0).

## Installation

#### [Carthage](https://github.com/Carthage/Carthage)

- Insert `github "ishkawa/APIKit" ~> 3.1` to your Cartfile.
- Insert `github "ishkawa/APIKit" ~> 5.0` to your Cartfile.
- Run `carthage update`.
- Link your app with `APIKit.framework` and `Result.framework` in `Carthage/Build`.

#### [CocoaPods](https://github.com/cocoapods/cocoapods)

- Insert `pod 'APIKit', '~> 3.1'` to your Podfile.
- Insert `pod 'APIKit', '~> 5.0'` to your Podfile.
- Run `pod install`.

Note: CocoaPods 1.1.0 is required to install APIKit 3.
Note: CocoaPods 1.4.0 is required to install APIKit 5.

## Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public struct MultipartFormDataBodyParameters: BodyParameters {

public extension MultipartFormDataBodyParameters {
/// Part represents single part of multipart/form-data.
public struct Part {
struct Part {
public enum Error: Swift.Error {
case illegalValue(Any)
case illegalFileURL(URL)
Expand Down
2 changes: 1 addition & 1 deletion Sources/APIKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.1.0</string>
<string>5.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
19 changes: 9 additions & 10 deletions Sources/APIKit/Request.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Result

/// `Request` protocol represents a request for Web API.
/// Following 5 items must be implemented.
Expand Down Expand Up @@ -62,39 +61,39 @@ public protocol Request {
}

public extension Request {
public var parameters: Any? {
var parameters: Any? {
return nil
}

public var queryParameters: [String: Any]? {
var queryParameters: [String: Any]? {
guard let parameters = parameters as? [String: Any], method.prefersQueryParameters else {
return nil
}

return parameters
}

public var bodyParameters: BodyParameters? {
var bodyParameters: BodyParameters? {
guard let parameters = parameters, !method.prefersQueryParameters else {
return nil
}

return JSONBodyParameters(JSONObject: parameters)
}

public var headerFields: [String: String] {
var headerFields: [String: String] {
return [:]
}

public var dataParser: DataParser {
var dataParser: DataParser {
return JSONDataParser(readingOptions: [])
}

public func intercept(urlRequest: URLRequest) throws -> URLRequest {
func intercept(urlRequest: URLRequest) throws -> URLRequest {
return urlRequest
}

public func intercept(object: Any, urlResponse: HTTPURLResponse) throws -> Any {
func intercept(object: Any, urlResponse: HTTPURLResponse) throws -> Any {
guard 200..<300 ~= urlResponse.statusCode else {
throw ResponseError.unacceptableStatusCode(urlResponse.statusCode)
}
Expand All @@ -103,7 +102,7 @@ public extension Request {

/// Builds `URLRequest` from properties of `self`.
/// - Throws: `RequestError`, `Error`
public func buildURLRequest() throws -> URLRequest {
func buildURLRequest() throws -> URLRequest {
let url = path.isEmpty ? baseURL : baseURL.appendingPathComponent(path)
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
throw RequestError.invalidBaseURL(baseURL)
Expand Down Expand Up @@ -140,7 +139,7 @@ public extension Request {

/// Builds `Response` from response `Data`.
/// - Throws: `ResponseError`, `Error`
public func parse(data: Data, urlResponse: HTTPURLResponse) throws -> Response {
func parse(data: Data, urlResponse: HTTPURLResponse) throws -> Response {
let parsedObject = try dataParser.parse(data: data)
let passedObject = try intercept(object: parsedObject, urlResponse: urlResponse)
return try response(from: passedObject, urlResponse: urlResponse)
Expand Down
Loading

0 comments on commit 862a8f8

Please sign in to comment.