Skip to content

Commit

Permalink
Support Swift 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
E13Lau committed Apr 2, 2019
1 parent 0837a16 commit b0b10ae
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 46 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "Carthage/Checkouts/Result"]
path = Carthage/Checkouts/Result
url = https://github.com/antitypical/Result.git
28 changes: 14 additions & 14 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 @@ -56,7 +53,7 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
7F4A73AC1CA839AE002554B1 /* PBXContainerItemProxy */ = {
BDFB151A2253060A00D8C94B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 7F45FCD41A94D02C006863BB /* Project object */;
proxyType = 1;
Expand All @@ -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 @@ -388,7 +380,7 @@
buildRules = (
);
dependencies = (
7F4A73AD1CA839AE002554B1 /* PBXTargetDependency */,
BDFB151B2253060A00D8C94B /* PBXTargetDependency */,
);
name = Tests;
productName = APIKitTests;
Expand All @@ -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 @@ -509,10 +501,10 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
7F4A73AD1CA839AE002554B1 /* PBXTargetDependency */ = {
BDFB151B2253060A00D8C94B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 141F12161C1C9ABE0026D415 /* APIKit */;
targetProxy = 7F4A73AC1CA839AE002554B1 /* PBXContainerItemProxy */;
targetProxy = BDFB151A2253060A00D8C94B /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

Expand All @@ -524,8 +516,10 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -536,8 +530,10 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -546,6 +542,7 @@
baseConfigurationReference = 141F12401C1C9EA30026D415 /* Tests.xcconfig */;
buildSettings = {
INFOPLIST_FILE = Tests/APIKitTests/Info.plist;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -555,13 +552,15 @@
buildSettings = {
INFOPLIST_FILE = Tests/APIKitTests/Info.plist;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
7F45FCF11A94D02C006863BB /* Debug */ = {
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 @@ -583,6 +582,7 @@
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 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
12 changes: 7 additions & 5 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
- Mac OS 10.11 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/release/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.1.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.0.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
1 change: 0 additions & 1 deletion Sources/APIKit/Session.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Result

private var taskRequestKey = 0

Expand Down
2 changes: 0 additions & 2 deletions Sources/APIKit/Unavailable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2016 Yosuke Ishikawa. All rights reserved.
//

import Result

// MARK: - Protocols

@available(*, unavailable, renamed: "Request")
Expand Down
1 change: 0 additions & 1 deletion Tests/APIKitTests/SessionTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation
import APIKit
import XCTest
import Result

class SessionTests: XCTestCase {
var adapter: TestSessionAdapter!
Expand Down
1 change: 0 additions & 1 deletion Tests/APIKitTests/TestComponents/HTTPStub.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import Dispatch
import Result

class HTTPStub: URLProtocol {
static var stubResult: Result<Data, NSError> = .success(Data())
Expand Down

0 comments on commit b0b10ae

Please sign in to comment.