Refactoring

This commit is contained in:
Ivan Babkin 2019-07-01 15:38:10 +03:00
parent b3dcd06298
commit 4d21fe0577
1 changed files with 3 additions and 3 deletions

View File

@ -40,12 +40,12 @@ public extension Encodable {
/// - Returns: URLQueryItems array
func asUrlQueryItems() throws -> [URLQueryItem] {
return try toJSON().map {
if let value = $1 as? Encodable,
let jsonData = try? JSONSerialization.data(withJSONObject: value.toJSON(), options: []),
if ($1 is [String: Any] || $1 is [Any]),
let jsonData = try? JSONSerialization.data(withJSONObject: $1, options: []),
let jsonString = String(data: jsonData, encoding: .utf8) {
return URLQueryItem(name: $0, value: jsonString)
} else if let value = $1 as? CustomStringConvertible {
return URLQueryItem(name: $0, value: "\(value)")
return URLQueryItem(name: $0, value: value.description)
} else {
throw LeadKitError.failedToEncodeQueryItems
}