Created
May 15, 2019 19:28
-
-
Save quangDecember/11e078c12d9b2540fe78c8703262e6f9 to your computer and use it in GitHub Desktop.
Construct URL using URLComponents, ensure safe path, percent encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLComponents { | |
init(scheme: String = "https", host: String, path: [String], queries: [URLQueryItem]?) { | |
self = URLComponents.init() | |
self.scheme = scheme | |
self.host = host | |
var p = path | |
p.insert("/", at: 0) | |
self.path = NSString.path(withComponents: p) | |
self.queryItems = queries | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment