Reputation: 341
I wanna give Alamofire request with the following
var postParameters=[
"x" : "value1",
"y" : "value2",
"y" : "value3"
]
How do I achieve this?.
I can't give it as any collection. I am in need to give it as a separate parameters only.
Any hint will be helpful for me. Thanks in advance.
Upvotes: 4
Views: 1491
Reputation: 8327
While there is no possible way of creating a dictionary with duplicate keys, there is a way to pass these kind of parameters to your server by using an array:
let postParameters: [String: Any] = [
"x" : "value1",
"y" : ["value2", "value3"]
]
then when you call request
function of Alamofire, you pass a new instance of URLEncoding
as encoding
parameter and specify the way that you want to encode arrays, like this:
AF.request(
"url",
method: .post,
parameters: postParameters,
encoding: URLEncoding(arrayEncoding: .noBrackets)
)
Upvotes: 1
Reputation: 382
It's not possible to create dict like that in iOS, instead, you can do multiple API calls.
Upvotes: 1