Created
November 27, 2015 17:26
-
-
Save dedeexe/39a0f93774fb4ee401ef to your computer and use it in GitHub Desktop.
Convert a dictionary to string joining each key/value for a keyValueToken and mark each group by another token
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 joinKeyValuesFor(keyValueToken : String, groupedByToken:String ) -> String | |
{ | |
var str = "" | |
for (key, value) in self | |
{ | |
if str != "" | |
{ | |
str += groupedByToken | |
} | |
str += "\(key)\(keyValueToken)\(value)" | |
} | |
return str | |
} | |
} | |
["user":"guest", "password":"12345", "grant":"password"].joinKeyValuesFor("=", groupedByToken: "&") | |
//Returns : "grant=password&user=dede&password=12345" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment