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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started