Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire Parameters - NSDictionary is not convertible to [String : AnyObject]

So I am trying to send a json object as parameters with Alamofire. I think I have followed example in their documentation but I get this error with the method call.

Code with Error

@IBAction func saveButton(sender: AnyObject) {
    var url = "http://b857aaa4.ngrok.io/recruit"

    let parameters = [
        "_id" : firstNameTextField.text,
        "alt_email" : "",
        "forename" : firstNameTextField.text,
        "phone" : recruteePhone.text,
        "recruiter" : [
            "comments" : "",//TODO comments
            "date_met" : "",//TODO tdoays date
            "email" : "",//TODO recruiter email
            "event_name" : ""//TODO event name
        ],
        "surname" : lastNameTextField.text
    ]


    Alamofire.request(.PUT, url, parameters: parameters, encoding: .JSON)
        .responseJSON { (req, res, json, error) in
            if(error != nil) {
                NSLog("Error: \(error)\n")
            } else {
                var json = JSON(json!);
                println("success");
            }
    }
like image 868
ObligatorRory Avatar asked Aug 11 '15 20:08

ObligatorRory


1 Answers

Declare parameters as

    let parameters: [String: AnyObject] = [

and it compiles okay.

like image 85
rshev Avatar answered Nov 04 '22 18:11

rshev