Skip to content

Commit

Permalink
Merge pull request Moya#1995 from Moya/development-swift-5.1-updates
Browse files Browse the repository at this point in the history
Development swift 5.1 updates
  • Loading branch information
sunshinejr authored Feb 27, 2020
2 parents c886fa2 + d3206d7 commit 86f2b1f
Show file tree
Hide file tree
Showing 53 changed files with 214 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
defaults: &defaults
macos:
xcode: 11.0.0
xcode: 11.3.1
parallelism: 1
shell: /bin/bash --login
environment:
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next

### Changed
- Moya's Swift version is now Swift 5.1. [#1931](https://github.com/Moya/Moya/pull/1931) by [@BasThomas](https://github.com/BasThomas).
# [14.0.0] - 2020-02-15

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Examples/Basic/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ViewController: UITableViewController {
// MARK: - Table View

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return repos.count
repos.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
2 changes: 1 addition & 1 deletion Examples/Multi-Target/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ViewController: UITableViewController {
// MARK: - Table View

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return repos.count
repos.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
6 changes: 2 additions & 4 deletions Examples/_shared/GiphyAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum Giphy {
}

extension Giphy: TargetType {
public var baseURL: URL { return URL(string: "https://upload.giphy.com")! } // swiftlint:disable:this force_unwrapping
public var baseURL: URL { URL(string: "https://upload.giphy.com")! } // swiftlint:disable:this force_unwrapping
public var path: String {
switch self {
case .upload:
Expand All @@ -35,9 +35,7 @@ extension Giphy: TargetType {
}
}

public var headers: [String: String]? {
return nil
}
public var headers: [String: String]? { nil }

// swiftlint:disable:next force_unwrapping
static let animatedBirdData = Data(base64Encoded: "R0lGODlhJAAlAMMDAAAAAP/yAB0bAP///5mZmREAAHNzc/7+/hsZAP/xAPr69//0AB4bAGZmZgAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFZAAOACwAAAAAJAAlAAAEY9DJSau9OOvNu/9gKI5kaZ5oqq5s675wLM90DNx3ewc8n6eAntCHCvIYjACyBzgZGYcDVEosPaOEQ5YaaJKu0jDXOwKLx9YeMrlmpofwrskYr77rcqd6aXfSfWQqOD81hYYYEQAh+QQFCgAOACwNABYACQAGAAAEDjDISau1bGaZmQ/edgURACH5BAlkAA4ALAAAAAAkACUAAAQ+0MlJq7046827/2AojmRpnmiqrmzrvnAsz3Rt3yvDOLrLHIdfkCUkHIzDFfAnJAKDz12up5PirtisdsulRQAAIfkECRQADgAsCQAQABIAFQAABHfQuSKrlRRPbTP9RhFeWGgATliIZLqy09piMg1faha/11tPhlll5DighBXAQXJEOppNBkJKRTCTDmlgy91OoQwuAuElb5vmAEIxHrO5DElYrWDX12+1I42v+/MBDHNlbW0LYmldil1ji2qJYnuOjlYShVJjmG0SEQAh+QQJCgAOACwKAA4ADwAVAAAEVtBJCWqd2NXA+cVAJ3pTOI4AdaLaem4dwwSyCNPHweSzZ+4HQpDn4wB3R9KPRwykWsZZjaQB9EaMT8qK3VImsnBJkylTPuazJV21GJ6ZrdxgfsPXoE8EACH5BAkAAA4ALAIAEAAfAA8AAARf0MlJJ7i36q1v+F/GjRZohuQIgAwTtCCQbut7HMztBjKJlbYDQahDSX5HTK+WwzlxRqVsKaoFmztecnm0eFguWEzk6HGYp8/OPDuqT+t2xdqqx+Tz9B0/t4bYfBRSbREAIfkECQAADgAsCwAHAA8AFgAABF/QOQCavI1eqXff2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9c5kQMjcqVmsR9wSBxKcMMXUmljVq8Wj0l1otWEVY4RRCaHWc+yeoUurcvn9jilAsXlb3u7k7/vmXB+f09NaBEAIfkECQAADgAsCwAHAA8AGAAABGPQOQCavI1eqXff2TZZXlgC3sd9GSpOFUe+junS3JRSN7wGQGBHAwAyGIGjUFdMHg6MJzLgKkYPBKyUOjFKoVtq8woOU4JHZDp4Drrf7bc8LnejmkYlm1O3X/BzInRiODwqDhEAIfkECQoADgAsCgAMAA8AFwAABFrQSQlqndjVwPnFAMcwwehNYXkczEoGAKUeBO3CmuiyN5y2u95GZBq9fJ2kErlcDpvJWIp4xOWgJ83UGdNolZduV2tBUTJoKXpdXqMs4zTcEDeHAYY1fdx+dyMAIfkECQoADgAsCQAaABIACwAABEHQSclQvWhqVwNjHhhYm8gcx5kGbCYhrEoc8xpTMXqq3ejAOR0qBQyxYh9LcnFEFI/Q6OjZpLZ+0qzv5VR+Kl1XBAAh+QQJCgAOACwJAAwADwAPAAAEP9BJCWqd2NXA+cVAJ3pTyDFMgHYAdR4HA6dBa8oHkc/ePce8mu8X3JxWKJpwxCSZmiQNlFXqJKmgZy9TsrQwEQAh+QQJCgAOACwKABQADwAPAAAEP9BJCWqd2NXA+cVAJ3pTyDFMgHYAdR4HA6dBa8oHkc/ePce8mu8X3JxWKJpwxCSZmiQNlFXqJKmgZy9TsrQwEQAh+QQFCgAOACwKAA8ADwAPAAAEP9BJCWqd2NXA+cVAJ3pTyDFMgHYAdR4HA6dBa8oHkc/ePce8mu8X3JxWKJpwxCSZmiQNlFXqJKmgZy9TsrQwEQA7", options: [])!
Expand Down
16 changes: 7 additions & 9 deletions Examples/_shared/GitHubAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let gitHubProvider = MoyaProvider<GitHub>(plugins: [NetworkLoggerPlugin(configur

private extension String {
var urlEscaped: String {
return self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
}
}

Expand All @@ -33,7 +33,7 @@ public enum GitHub {
}

extension GitHub: TargetType {
public var baseURL: URL { return URL(string: "https://api.github.com")! }
public var baseURL: URL { URL(string: "https://api.github.com")! }
public var path: String {
switch self {
case .zen:
Expand All @@ -44,9 +44,8 @@ extension GitHub: TargetType {
return "/users/\(name.urlEscaped)/repos"
}
}
public var method: Moya.Method {
return .get
}
public var method: Moya.Method { .get }

public var task: Task {
switch self {
case .userRepositories:
Expand All @@ -73,13 +72,12 @@ extension GitHub: TargetType {
return "[{\"name\": \"\(name)\"}]".data(using: String.Encoding.utf8)!
}
}
public var headers: [String: String]? {
return nil
}
public var headers: [String: String]? { nil }

}

public func url(_ route: TargetType) -> String {
return route.baseURL.appendingPathComponent(route.path).absoluteString
route.baseURL.appendingPathComponent(route.path).absoluteString
}

// MARK: - Response Handlers
Expand Down
7 changes: 3 additions & 4 deletions Examples/_shared/GitHubUserContentAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum GitHubUserContent {
}

extension GitHubUserContent: TargetType {
public var baseURL: URL { return URL(string: "https://raw.githubusercontent.com")! } // swiftlint:disable:this force_unwrapping
public var baseURL: URL { URL(string: "https://raw.githubusercontent.com")! } // swiftlint:disable:this force_unwrapping
public var path: String {
switch self {
case .downloadMoyaWebContent(let contentPath):
Expand All @@ -33,9 +33,8 @@ extension GitHubUserContent: TargetType {
return Giphy.animatedBirdData
}
}
public var headers: [String: String]? {
return nil
}
public var headers: [String: String]? { nil }

}

private let defaultDownloadDestination: DownloadDestination = { temporaryURL, response in
Expand Down
2 changes: 1 addition & 1 deletion Moya.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.watchos.deployment_target = '3.0'
s.source = { :git => "https://github.com/Moya/Moya.git", :tag => s.version }
s.default_subspec = "Core"
s.swift_version = '5.0'
s.swift_version = '5.1'
s.cocoapods_version = '>= 1.4.0'

s.subspec "Core" do |ss|
Expand Down
4 changes: 4 additions & 0 deletions Moya.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
A6304A7E74FA3B04C9B10B63 /* AccessTokenPluginSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BAAD7EC02607A52AD3EF1E /* AccessTokenPluginSpec.swift */; };
A8C55515DFA147BE4159B40A /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EFCB6731C60D3830DA5D2CB /* Response.swift */; };
AB5048DC5042B016964EE958 /* MoyaProvider+Reactive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371C174EF53873DE04BB159E /* MoyaProvider+Reactive.swift */; };
B2CD7F4F23A6F1BA007F67AC /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2CD7F4E23A6F1BA007F67AC /* Atomic.swift */; };
B4ABD55950B0E70BF44E79C6 /* MoyaProviderIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E52DC541FD052ABA625D2A /* MoyaProviderIntegrationTests.swift */; };
B5A7124CF285D8EC7F89C1AD /* CredentialsPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884642F58B074C95261DCA86 /* CredentialsPlugin.swift */; };
B950CAA84C0656EB11E316FB /* MultiTargetSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D11E4BE1D5112E6972AD09F /* MultiTargetSpec.swift */; };
Expand Down Expand Up @@ -204,6 +205,7 @@
9C38151BF038BA0B61EF5A62 /* TargetType.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TargetType.swift; sourceTree = "<group>"; };
B184F8E91A84A02E209EEB91 /* MultipartFormData.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MultipartFormData.swift; sourceTree = "<group>"; };
B1F68927EA26EBDB45E82C8C /* MoyaProviderSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MoyaProviderSpec.swift; sourceTree = "<group>"; };
B2CD7F4E23A6F1BA007F67AC /* Atomic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Atomic.swift; sourceTree = "<group>"; };
C79C5F376B4A2C3F70051980 /* Error+MoyaSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "Error+MoyaSpec.swift"; sourceTree = "<group>"; };
C841AA621AEC61FAEA0CA019 /* MoyaProvider+ReactiveSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "MoyaProvider+ReactiveSpec.swift"; sourceTree = "<group>"; };
CC115388D44D0DB7A753E9BB /* AccessTokenPlugin.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AccessTokenPlugin.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -308,6 +310,7 @@
331A6D3090D9773091435406 /* Moya */ = {
isa = PBXGroup;
children = (
B2CD7F4E23A6F1BA007F67AC /* Atomic.swift */,
149749421F8923EC00FA4900 /* AnyEncodable.swift */,
5C2B20158E599EDBE51D7AB2 /* Cancellable.swift */,
3FF1994427C5440527B03B31 /* Endpoint.swift */,
Expand Down Expand Up @@ -832,6 +835,7 @@
3AF7063CBE1F9626FB32D933 /* Cancellable.swift in Sources */,
85F6042E22A018BB00063320 /* RequestTypeWrapper.swift in Sources */,
49C61E884A595E94758B5643 /* Endpoint.swift in Sources */,
B2CD7F4F23A6F1BA007F67AC /* Atomic.swift in Sources */,
FB223B5C3B7D4AA5261E25EA /* Image.swift in Sources */,
EDBA10DB0D0E35C1474AAB4D /* Moya+Alamofire.swift in Sources */,
15D3A2BD1223B59E2BBE09F0 /* MoyaError.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Moya.xcodeproj/xcshareddata/xcschemes/Moya.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
shouldUseLaunchSchemeArgsEnv = "YES"
enableThreadSanitizer = "YES">
<Testables>
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ end

def device_os
return {
ios: "13.0",
tvos: "13.0"
ios: "13.3",
tvos: "13.3"
}
end

Expand Down
31 changes: 31 additions & 0 deletions Sources/Moya/Atomic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Atomic.swift
// Moya
//
// Created by Luciano Almeida on 15/12/19.
//

import Foundation

@propertyWrapper
final class Atomic<Value> {
private var lock: NSRecursiveLock = NSRecursiveLock()

private var value: Value

var wrappedValue: Value {
get {
lock.lock(); defer { lock.unlock() }
return value
}

set {
lock.lock(); defer { lock.unlock() }
value = newValue
}
}

init(wrappedValue value: Value) {
self.value = value
}
}
2 changes: 1 addition & 1 deletion Sources/Moya/Cancellable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public protocol Cancellable {
internal class CancellableWrapper: Cancellable {
internal var innerCancellable: Cancellable = SimpleCancellable()

var isCancelled: Bool { return innerCancellable.isCancelled }
var isCancelled: Bool { innerCancellable.isCancelled }

internal func cancel() {
innerCancellable.cancel()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Moya/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ open class Endpoint {

/// Convenience method for creating a new `Endpoint` with the same properties as the receiver, but with added HTTP header fields.
open func adding(newHTTPHeaderFields: [String: String]) -> Endpoint {
return Endpoint(url: url, sampleResponseClosure: sampleResponseClosure, method: method, task: task, httpHeaderFields: add(httpHeaderFields: newHTTPHeaderFields))
Endpoint(url: url, sampleResponseClosure: sampleResponseClosure, method: method, task: task, httpHeaderFields: add(httpHeaderFields: newHTTPHeaderFields))
}

/// Convenience method for creating a new `Endpoint` with the same properties as the receiver, but with replaced `task` parameter.
open func replacing(task: Task) -> Endpoint {
return Endpoint(url: url, sampleResponseClosure: sampleResponseClosure, method: method, task: task, httpHeaderFields: httpHeaderFields)
Endpoint(url: url, sampleResponseClosure: sampleResponseClosure, method: method, task: task, httpHeaderFields: httpHeaderFields)
}

fileprivate func add(httpHeaderFields headers: [String: String]?) -> [String: String]? {
Expand Down
18 changes: 3 additions & 15 deletions Sources/Moya/Moya+Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public typealias DownloadDestination = Alamofire.DownloadRequest.Destination
/// Make the Alamofire Request type conform to our type, to prevent leaking Alamofire to plugins.
extension Request: RequestType {
public var sessionHeaders: [String: String] {
return delegate?.sessionConfiguration.httpAdditionalHeaders as? [String: String] ?? [:]
delegate?.sessionConfiguration.httpAdditionalHeaders as? [String: String] ?? [:]
}
}

Expand Down Expand Up @@ -107,22 +107,10 @@ extension DownloadRequest: Requestable {
}

final class MoyaRequestInterceptor: RequestInterceptor {
private let lock: NSRecursiveLock = NSRecursiveLock()

var prepare: ((URLRequest) -> URLRequest)?
private var internalWillSend: ((URLRequest) -> Void)?

var willSend: ((URLRequest) -> Void)? {
get {
lock.lock(); defer { lock.unlock() }
return internalWillSend
}

set {
lock.lock(); defer { lock.unlock() }
internalWillSend = newValue
}
}
@Atomic
var willSend: ((URLRequest) -> Void)?

init(prepare: ((URLRequest) -> URLRequest)? = nil, willSend: ((URLRequest) -> Void)? = nil) {
self.prepare = prepare
Expand Down
2 changes: 1 addition & 1 deletion Sources/Moya/MoyaProvider+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
/// These functions are default mappings to `MoyaProvider`'s properties: endpoints, requests, session etc.
public extension MoyaProvider {
final class func defaultEndpointMapping(for target: Target) -> Endpoint {
return Endpoint(
Endpoint(
url: URL(target: target).absoluteString,
sampleResponseClosure: { .networkResponse(200, target.sampleData) },
method: target.method,
Expand Down
15 changes: 4 additions & 11 deletions Sources/Moya/MoyaProvider+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ public extension MoyaProvider {
}

if trackInflights {
lock.lock()
var inflightCompletionBlocks = self.inflightRequests[endpoint]
inflightCompletionBlocks?.append(pluginsWithCompletion)
self.inflightRequests[endpoint] = inflightCompletionBlocks
lock.unlock()
self.internalInflightRequests[endpoint] = inflightCompletionBlocks

if inflightCompletionBlocks != nil {
return cancellableToken
} else {
lock.lock()
self.inflightRequests[endpoint] = [pluginsWithCompletion]
lock.unlock()
self.internalInflightRequests[endpoint] = [pluginsWithCompletion]
}
}

Expand All @@ -65,10 +61,7 @@ public extension MoyaProvider {
let networkCompletion: Moya.Completion = { result in
if self.trackInflights {
self.inflightRequests[endpoint]?.forEach { $0(result) }

self.lock.lock()
self.inflightRequests.removeValue(forKey: endpoint)
self.lock.unlock()
self.internalInflightRequests.removeValue(forKey: endpoint)
} else {
pluginsWithCompletion(result)
}
Expand Down Expand Up @@ -167,7 +160,7 @@ private extension MoyaProvider {
private func interceptor(target: Target) -> MoyaRequestInterceptor {
return MoyaRequestInterceptor(prepare: { [weak self] urlRequest in
return self?.plugins.reduce(urlRequest) { $1.prepare($0, target: target) } ?? urlRequest
})
})
}

private func setup(interceptor: MoyaRequestInterceptor, with target: Target, and request: Request) {
Expand Down
Loading

0 comments on commit 86f2b1f

Please sign in to comment.