I have an array of dictionaries that I am trying to post to Alamofire with the help of SwiftyJSON.
The api is set to take:
[
{
"imageUrl": "someimage3.jpg"
},
{
"imageUrl": "someimage4.jpg"
}
]
My array with image objects when printed out looks like this with the imageUrl key and image name for the value.
uploadedFiles = [
[imageUrl: "someimage.jpg"],
[imageUrl: "someimage2.jpg"]
]
I'm trying to convert the array of dictionaries into the format needed for the body. I'm not quite sure how to get them to be [String: AnyObject]
var body: [String: AnyObject] = [:]
let paramsJSON = JSON(uploadedFiles)
body = paramsJSON
alamofire post
Alamofire.request("\(BASE_URL)mainimages/\(someid)", method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseString { (response) in
if response.result.error == nil {
let status = response.response?.statusCode
completion(true, status)
} else {
completion(false, nil)
debugPrint(response.result.error as Any)
}
}