Skip to content

Instantly share code, notes, and snippets.

@koogawa
Created July 25, 2015 04:08
Show Gist options
  • Save koogawa/f0987d6425a9da63d121 to your computer and use it in GitHub Desktop.
Save koogawa/f0987d6425a9da63d121 to your computer and use it in GitHub Desktop.
テスト:DictionaryからAPIに投げるSTRINGを作るメソッド #cswift #CodePiece
func buildQueryString(fromDictionary parameters: [String: String]) -> String {
var urlVars = [String]()
for (key, var val) in parameters {
val = val.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
urlVars += [key + "=" + "\(val)"]
}
return (!urlVars.isEmpty ? "?" : "") + join("&", urlVars)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment