Error: I used Swift 4 as an additional parameter in the request. Why do I have to pass parameters like [String: Any]?

Alamofire.request(APPURL.GetAccounts, method: .post, parameters: transactionData, encoding: JSONEncoding.default, headers: nil).responseJSON { responseData in } 

My question is, what is the reason that limits me only to the fact that I can use a dictionary like [String: Any]?

Code:

 class func getAccounts( transactionData: [String:Any]?, withCompletionHandler: @escaping (_ response:AnyObject?)->(Void) ) { Alamofire.request(APPURL.GetAccounts, method: .post, parameters: transactionData, encoding: JSONEncoding.default, headers: nil).responseJSON { responseData in if((responseData.result.value) != nil) { let swiftyJsonVar = JSON(responseData.result.value!) if let resData = swiftyJsonVar["Accounts"].arrayObject { let resultData = resData as! [[String:AnyObject]] withCompletionHandler(resultData as AnyObject) }else{ withCompletionHandler(nil) } }else{ withCompletionHandler(nil) } } } 
+5
source share
1 answer

In JSON format, the key must always be a string, and the value can be of any type. This is how JSON works in Swift.

0
source

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


All Articles