Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 515
PerNil Avatar asked Nov 29 '22 21:11

PerNil


1 Answers

You need to set the type explicitly.

let headers : HTTPHeaders = [
    "Authorization": "Basic MY-API-KEY",
    "Content-Type" : "application/x-www-form-urlencoded"
]
like image 134
emeraldsanto Avatar answered Dec 18 '22 14:12

emeraldsanto