From 45117a9b0c554f0893ce0187c3a8dea3d7a095b2 Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 25 Jun 2018 11:29:55 +0200 Subject: [PATCH] Arrays now converted to string and passed as parameter Arrays now properly converted to string such as "['1', '2']" and passed to request as parameter. Fixes #293. --- Source/Request.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/Request.swift b/Source/Request.swift index 6767352..d92cab0 100644 --- a/Source/Request.swift +++ b/Source/Request.swift @@ -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 { @@ -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 + "]" + } } /**