0

i want to post array of dictionaries in alamofire, but some how it is not posting.i can use many ways but still not find the proper answer on it. Showing error "Extra argument 'method' in call" . Here is my code.

let userToken: HTTPHeaders = [
        "Content-Type": "application/json"
    ]
let parm = [
            [
                 "EmployeeID": id,
                 "Longitude":  longitude,
                 "Latitude":   latitude,
                 "GeoTime":    dateString,
                 "UserToken":  "g98XQdy8B}rQ7?Q"
            ]
          ]
postAttandance(apiUrl: postAttandanceURL, parameter: parm , tiket: userToken){
        (done) -> Void in
        if done{

        }
    }

func postAttandance(apiUrl : String , parameter : [[String : Any]] ,  tiket : HTTPHeaders , completion : @escaping (_ done : Bool) -> Void ){
    Alamofire.request(apiUrl, method : .post , parameters : parameter ,encoding : JSONEncoding.default,  headers : tiket).responseJSON { (response) in
        if response.result.isSuccess{
            let responsejson : JSON = JSON(response.result.value!)
            completion(true)
        }
    }
}
Mustaqeez Ahmad
  • 411
  • 4
  • 8
  • 1
    The `parameter` parameter of `Alamofire.request` function is typealias `Parameter`, which is `[String : Any]`, what you are passing to it is `[[String : Any]]`. As `Alamofire.request` function comes with default parameter values, any invalid parameter type assigned to the function will give you the error you are having now. – koropok May 24 '19 at 03:21
  • @koropok i want to post array of dictionaries like [ [String : Any] ] – Mustaqeez Ahmad May 24 '19 at 03:36
  • maybe you can try `[String : [String : Any]]`. – koropok May 24 '19 at 03:45
  • This may help you : https://stackoverflow.com/a/48537265/1042817 – Rocky May 24 '19 at 04:39
  • As @koropok suggested try doing something like this ["data": [ "EmployeeID": id, "Longitude": longitude, "Latitude": latitude, "GeoTime": dateString, "UserToken": "g98XQdy8B}rQ7?Q" ] ] – Cedan Misquith Jun 17 '19 at 05:31

0 Answers0