How not to hardcode parameter in swift?

Here is my Alamofire request to an API. Instead of hardcoding the origin, destination and date in the parameters variable. I want the user to input that in via a textfield. Would I change the data structure? I’m just asking for some guidelines, im stumped.

 enum Router: URLRequestConvertible { case QPXRequest()

 var URLRequest: NSURLRequest {
let URL = NSURL(string: "https://www.googleapis.com/qpxExpress/v1/trips/search?key=(api key here)&fields=trips(data/carrier/name),trips(tripOption/saleTotal)")!
let URLRequest = NSMutableURLRequest(URL: URL)

URLRequest.HTTPMethod = "POST"

var parameters = [
    "request": [
        "slice": [
            [
                "origin": "MEL",
                "destination": "LOS",
                "date": "2015-07-15"
            ]
        ],

        "passengers": [
            "adultCount": 1,
            "infantInLapCount": 0,
            "infantInSeatCount": 0,
            "childCount": 0,
            "seniorCount": 0
        ],
        "solutions": 10,
        "refundable": false
    ]
]

return ParameterEncoding.JSON.encode(URLRequest, parameters: parameters).0
}


Source: json

Leave a Reply