Alamofir complains about argument types

In the code below, Alamofire complains that it "cannot invoke" responseJSON "using a list of arguments like ((_, _, _, _) → _)". The same problem occurs when using the answer.

    func request(parameters: [String : AnyObject?], completionHandler: ((NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void)) -> Void {
      Alamofire.request(.POST, "localhost:8080/reserve", parameters:
            ["refreshToken": refreshToken,
             "accessToken": accessToken,
             "deviceToken": deviceToken],
            encoding: .JSON)
      .responseJSON { (request, response, data, error) in
            completionHandler(request, response, data, error)
      }
   }

Why is this happening?

+4
source share
1 answer

Your argument parametersis not typed correctly. It should be [String: AnyObject]?instead [String : AnyObject?].

After fixing this error, you must compile it again.

Otherwise, make sure token variables exist. If not, the compiler is confused and the error is not actually related to Alamofire.

+11
source

Source: https://habr.com/ru/post/1584347/


All Articles