Cannot convert value of type '[String : String]' to expected argument type 'HTTPHeaders?'
I´m trying to send mail from my iOS app with Mailgun
and Alarmofire
I found this piece of code but Xcode
generates error:
Cannot convert value of type '[String : String]' to expected argument type 'HTTPHeaders?'
Code:
let parameters = [
"from": "[email protected]",
"to": "[email protected]",
"subject": "Subject of the email",
"text": "This is the body of the email."]
let header = [
"Authorization": "Basic MY-API-KEY",
"Content-Type" : "application/x-www-form-urlencoded"]
let url = "https://api.mailgun.net/v3/MY-DOMAIN/messages"
Alamofire.request(url,
method: .post,
parameters: parameters,
encoding: URLEncoding.default,
headers: header)
.responseJSON { response in
print("Response: \(response)")
}
Any suggestions?
Solution 1:
You need to set the type explicitly.
let headers : HTTPHeaders = [
"Authorization": "Basic MY-API-KEY",
"Content-Type" : "application/x-www-form-urlencoded"
]