Skip to content

Instantly share code, notes, and snippets.

@gregheo
Created February 7, 2018 19:05
Show Gist options
  • Save gregheo/af0ff17111a2c402fa1e8d838229c61c to your computer and use it in GitHub Desktop.
Save gregheo/af0ff17111a2c402fa1e8d838229c61c to your computer and use it in GitHub Desktop.
Fake URL + url encoded query paramaters
import Foundation
let encodedString = "data=%7B%0D%0A%22coffee%22%3A%20%22coffee%22%2C%0D%0A%22beer%22%3A%20%22beer%22%2C%0D%0A%22has_bylaws%22%3A%20true%0D%0A%7D%0D%0A"
guard let c = URLComponents(string: "http://fake.com/?" + encodedString) else {
fatalError("could not generate url components! :(")
}
for item in c.queryItems ?? [] {
print("Got key \(item.name) with value \(item.value)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment