Created
February 6, 2018 02:58
-
-
Save hisoka0917/7474e1f76fb11f91199de36dfe4e25c4 to your computer and use it in GitHub Desktop.
Format Dictionary to url query
This file contains 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 Dictionary { | |
func urlQueryEncode() -> String { | |
return self | |
.map({ "\($0)=\($1)" }) | |
.joined(separator: "&") | |
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! | |
} | |
func queryParameters() -> String { | |
let parameterArray = self.map { (key, value) -> String in | |
return String(format: "%@=%@", | |
String(describing: key).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!, | |
String(describing: value).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) | |
} | |
return parameterArray.joined(separator: "&") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment