I'm trying to Post a Dictionairy to my backend using Alamofire:
This is my code:
func postCheckUserPhonenumbers(phonenumbers:[String], completionHandler: (([AnyObject?], AnyObject?) -> Void)) {
let urlString = Constant.apiUrl().stringByAppendingFormat(Constant.apiPostCheckUserPhonenumbers)
let phoneNumbersDictionary = phonenumbers.map({ ["number": $0] })
let json = JSON(phoneNumbersDictionary)
print(json)
Alamofire.request(.POST, urlString, parameters: phoneNumbersDictionary, encoding: .JSON).validate().responseJSON(completionHandler: {response in
if response.result.isSuccess{
if let json = response.result.value {
let json = JSON(json)
}
}
if response.result.isFailure{
}
})
}
It won't compile because the phoneNumbersDictionairy is not conforming to the expected argument:
The print(json) however is printing exactly what I have in my Postman though. This is the body I want to post. The printed statement:
[
{
"number" : "85555512"
},
{
"number" : "85551212"
},
{
"number" : "55648583"
}
]
My Postman:
How can I make this happen?