Skip to content

Instantly share code, notes, and snippets.

@stleamist
Created June 17, 2020 03:39
Show Gist options
  • Save stleamist/66e3dc0dfbbd917a651dae7e133f0713 to your computer and use it in GitHub Desktop.
Save stleamist/66e3dc0dfbbd917a651dae7e133f0713 to your computer and use it in GitHub Desktop.
import Foundation
extension URL {
init?(string: String?) {
guard let string = string else {
return nil
}
self.init(string: string)
}
static func percentEncoded(string: String?) -> URL? {
self.init(string: string?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment