Created
March 24, 2021 05:23
-
-
Save Enchan1207/278b3f2fe54cf534ea2e1858fc7dfbf2 to your computer and use it in GitHub Desktop.
配列を辞書に変換
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
// [[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