This commit is contained in:
William Cheng 2019-11-23 16:57:16 +08:00
commit 8cf34ca80f
6 changed files with 18 additions and 18 deletions

View File

@ -22,7 +22,7 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",") result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value { } else if let value: Any = item.value {
result[item.key] = "\(value)" result[item.key] = "\(value)"
@ -46,7 +46,7 @@ public struct APIHelper {
} }
public static func mapValueToPathItem(_ source: Any) -> Any { public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] { if let collection = source as? Array<Any?> {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
} }
return source return source
@ -54,7 +54,7 @@ public struct APIHelper {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? { public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
result.append(URLQueryItem(name: item.key, value: value)) result.append(URLQueryItem(name: item.key, value: value))
} else if let value = item.value { } else if let value = item.value {

View File

@ -22,7 +22,7 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",") result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value { } else if let value: Any = item.value {
result[item.key] = "\(value)" result[item.key] = "\(value)"
@ -46,7 +46,7 @@ public struct APIHelper {
} }
public static func mapValueToPathItem(_ source: Any) -> Any { public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] { if let collection = source as? Array<Any?> {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
} }
return source return source
@ -54,7 +54,7 @@ public struct APIHelper {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? { public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
result.append(URLQueryItem(name: item.key, value: value)) result.append(URLQueryItem(name: item.key, value: value))
} else if let value = item.value { } else if let value = item.value {

View File

@ -9,12 +9,12 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages. // Products define the executables and libraries produced by a package, and make them visible to other packages.
.library( .library(
name: "PetstoreClient", name: "PetstoreClient",
targets: ["PetstoreClient"]), targets: ["PetstoreClient"])
], ],
dependencies: [ dependencies: [
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.9.0"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.9.0"),
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.11.0"), .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.11.0")
], ],
targets: [ targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets are the basic building blocks of a package. A target can define a module or a test suite.
@ -23,6 +23,6 @@ let package = Package(
name: "PetstoreClient", name: "PetstoreClient",
dependencies: ["Alamofire", "PromiseKit"], dependencies: ["Alamofire", "PromiseKit"],
path: "PetstoreClient/Classes" path: "PetstoreClient/Classes"
), )
] ]
) )

View File

@ -22,7 +22,7 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",") result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value { } else if let value: Any = item.value {
result[item.key] = "\(value)" result[item.key] = "\(value)"
@ -46,7 +46,7 @@ public struct APIHelper {
} }
public static func mapValueToPathItem(_ source: Any) -> Any { public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] { if let collection = source as? Array<Any?> {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
} }
return source return source
@ -54,7 +54,7 @@ public struct APIHelper {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? { public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
result.append(URLQueryItem(name: item.key, value: value)) result.append(URLQueryItem(name: item.key, value: value))
} else if let value = item.value { } else if let value = item.value {

View File

@ -22,7 +22,7 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",") result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value { } else if let value: Any = item.value {
result[item.key] = "\(value)" result[item.key] = "\(value)"
@ -46,7 +46,7 @@ public struct APIHelper {
} }
public static func mapValueToPathItem(_ source: Any) -> Any { public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] { if let collection = source as? Array<Any?> {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
} }
return source return source
@ -54,7 +54,7 @@ public struct APIHelper {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? { public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
result.append(URLQueryItem(name: item.key, value: value)) result.append(URLQueryItem(name: item.key, value: value))
} else if let value = item.value { } else if let value = item.value {

View File

@ -22,7 +22,7 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",") result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value { } else if let value: Any = item.value {
result[item.key] = "\(value)" result[item.key] = "\(value)"
@ -46,7 +46,7 @@ public struct APIHelper {
} }
public static func mapValueToPathItem(_ source: Any) -> Any { public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] { if let collection = source as? Array<Any?> {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
} }
return source return source
@ -54,7 +54,7 @@ public struct APIHelper {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? { public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? [Any?] { if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",") let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
result.append(URLQueryItem(name: item.key, value: value)) result.append(URLQueryItem(name: item.key, value: value))
} else if let value = item.value { } else if let value = item.value {