Question: Swift - iOS Xcode 9.4 Write a function that generates a url string for making an HTTP GET request from a base url string and

Swift - iOS Xcode 9.4

Write a function that generates a url string for making an HTTP GET request from a base url string and a dictionary of query parameters.

- Lowercase the keys and values in the parameters.

- Replace any spaces in the keys and values of the parameters with the encoded character "%20".

- The order the parameters appear in the final query string is not important.

- Don't forget edge cases like an empty parameter dictionary.

Notes:

- Your function MUST work with the commented out function calls below!

- Look at the example output for how you need to construct your function

- I will not use any harder examples to grade than in the example calls below.

- You should explore some of the methods available on arrays and on strings (in both Swift and using the Foundation library which is already imported)

//let url1: String = httpGetUrl(baseUrl: "http://boardgames.com/game", parameters: ["Genre": "Strategy", "name": "Settlers Of Catan", "User Rating": "high"])

//let url2: String = httpGetUrl(baseUrl: "http://boardgames.com/game", parameters: [:])

//// Sample Output: query params can be in any order

//print(url1) // "http://boardgames.com/game?user%20rating=high&name=settlers%20of%20catan&genre=strategy"

//print(url2) // "http://boardgames.com/game"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!