I have a POST body paramter like this:
{
"id": 0,
"name": "string",
"contactInfo": "string",
"message": "string"
}
So since i am using the Alamofire for posting the parameters i am describing the post body dictionary like this:
let body = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message]
class func postUserFeedback(userID: Int, userName: String, contactInfo: String, message: String,completionHandler: @escaping (FeedbackResponse?) -> Void) {
let body = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message]
request(route: .userFeedback, body: body).responseObject { (response: DataResponse<FeedbackResponse>) in
response.result.ifSuccess({
completionHandler(response.result.value)
})
response.result.ifFailure {
completionHandler(nil)
}
}
}
But i am getting the error like this:
What i am doing wrong in this syntax?
If the type could not be inferred you have to annotate
let body : [String:Any] = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message]
or bridge cast it:
let body = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message] as [String:Any]