Skip to content

Instantly share code, notes, and snippets.

@rodericj
Forked from gregheo/url components.swift
Last active February 7, 2018 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodericj/ad666156a743bd476c2d5c195e31e7fc to your computer and use it in GitHub Desktop.
Save rodericj/ad666156a743bd476c2d5c195e31e7fc 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://fakenews.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