Skip to content

Commit

Permalink
Arrays now converted to string and passed as parameter
Browse files Browse the repository at this point in the history
Arrays now properly converted to string such as "['1', '2']" and passed to request as parameter.
Fixes daltoniam#293.
  • Loading branch information
LinusGeffarth authored Jun 25, 2018
1 parent 661ff94 commit 45117a9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Source/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension Dictionary: HTTPParameterProtocol {
Support for the Array type as an HTTPParameter.
*/
extension Array: HTTPParameterProtocol {

/*
public func createPairs(_ key: String?) -> [HTTPPair] {
var collect = [HTTPPair]()
for v in self {
Expand All @@ -148,6 +148,19 @@ extension Array: HTTPParameterProtocol {
}
return collect
}
*/

public func createPairs(_ key: String?) -> [HTTPPair] {
let pair: HTTPPair = HTTPPair(key: (key != nil ? "\(key!)" : key), value: self.stringRepresentation)
return [pair]
}

var stringRepresentation: String {
var str = "["
self.forEach { str += "\($0)," }
str = String(str.dropLast()) // drops last comma
return str + "]"
}
}

/**
Expand Down

0 comments on commit 45117a9

Please sign in to comment.