-2

How to post an array using Alamofire. Alamofire request takes only Dictionary type as a parameter: [String : Any].

But I want to pass an array as a parameter, not Dictionary.

Alamofire.request(url, method: .post, parameters: [String : Any], encoding: JSONEncoding.default, headers: [:])

Is there any way to solve it ..?

Keshu R.
  • 5,045
  • 1
  • 18
  • 38

1 Answers1

0
var request = URLRequest(url: try! "your api".asURL())
request.httpMethod = "POST"
let arrParam = ["abc", "xyz"]
request.httpBody = try! JSONSerialization.data(withJSONObject: arrParam)
Alamofire.request(request).responseJSON { response in
    switch (response.result) {
    case .success:
        //success code here
    case .failure(let error):
        //failure code here
    }
}
Chetan Hedamba
  • 293
  • 2
  • 9