Currently, my application uses AWS API Gateway and Alamofire to access various lambda functions that act as my backend.
I need to send an array as one of the parameters to one of these API endpoints, because I use the following code:
var interests : [String] interests = globalInterests.map({ (interest) -> String in return interest.id! }) // Parameters needed by the API let parameters: [String: AnyObject] = [ "name" : name, "lastName" : lastName, "interests" : interests ] // Sends POST request to the AWS API Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON).responseJSON { response in // Process Response switch response.result { case .Success: print("Sucess") case .Failure(let error): print(error) } }
But this does not work because the array is not recognized by the API, but if I create a βstaticβ array
let interests = ["a", "b", "c"]
Everything works as expected.
How can I fix this situation, given that the array of interests comes from another part of the code, how can I declare or build it?
A friend managed to accomplish this on Android using
ArrayList<String>
EDIT:
Printing an array of parameters shows me the following:
["name":test, "interests": <_TtCs21_SwiftDeferredNSArray 0x7b05ac00>( 103, 651, 42), "lastName": test]