Skip to content

Instantly share code, notes, and snippets.

@Enchan1207
Created March 24, 2021 05:23
Show Gist options
  • Save Enchan1207/278b3f2fe54cf534ea2e1858fc7dfbf2 to your computer and use it in GitHub Desktop.
Save Enchan1207/278b3f2fe54cf534ea2e1858fc7dfbf2 to your computer and use it in GitHub Desktop.
配列を辞書に変換
// [[String]] -> [String: String]
let params = [
["key1", "value4"],
["key2", "value5"],
["key3", "value6"],
]
let b = params.reduce([String:String]()) { (query, param) -> [String:String] in
var q = query
q.updateValue(param[1], forKey: param[0])
return q
}
// $ print(b)
// -> ["key3": "value6", "key1": "value4", "key2": "value5"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment