init()
init(minimumCapacity : Int)
init<S>(uniqueKeysWithValues : S)
init<S>(grouping: S, by: (S.Element) -> Key)
Availability
Technology
keysAndValues
A sequence of key-value pairs to use for the new dictionary. キー値ペアからなるシーケンス、新しい辞書に使うためのもの。
combine
A closure that is called with the values for any duplicate keys that are encountered. The closure returns the desired value for the final dictionary. あるクロージャで、出くわす何らかの重複キーに対するそれら値とともに呼ばれます。このクロージャは、最終的な辞書に対して望む値を返します。
You use this initializer to create a dictionary when you have a sequence of key-value tuples that might have duplicate keys. As the dictionary is built, the initializer calls the combine
closure with the current and new values for any duplicate keys. Pass a closure as combine
that returns the value to use in the resulting dictionary: The closure can choose between the two values, combine them to produce a new value, or even throw an error.
あなたは、重複キーを持つかもしれないキー値タプルのシーケンスをあなたが持つ場合、このイニシャライザを使って辞書を作成してください。辞書が組み立てられるとき、このイニシャライザはcombine
クロージャを何らかの重複キーに対してその現在および新規の値とともに呼び出します。あるクロージャをcombine
として渡してください、それは結果の辞書において使う値を返します:そのクロージャは2つの値のどちらかを選ぶこと、それらを結合して新しい値を生成すること、またはエラーをスローすることさえ出来ます。
The following example shows how to choose the first and last values for any duplicate keys: 以下の例は、あらゆる重複キーに対して最初と最後の値を選択する方法を示します:
let pairsWithDuplicateKeys = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
let firstValues = Dictionary(pairsWithDuplicateKeys,
uniquingKeysWith: { (first, _) in first })
// ["b": 2, "a": 1]
let lastValues = Dictionary(pairsWithDuplicateKeys,
uniquingKeysWith: { (_, last) in last })
// ["b": 4, "a": 3]
init()
init(minimumCapacity : Int)
init<S>(uniqueKeysWithValues : S)
init<S>(grouping: S, by: (S.Element) -> Key)