init(dictionaryLiteral:)
Creates a dictionary initialized with a dictionary literal.
Declaration
init(dictionaryLiteral elements: (Key, Value)...)Parameters
- elements:
The key-value pairs that will make up the new dictionary. Each key in
elementsmust be unique.
Discussion
Do not call this initializer directly. It is called by the compiler to handle dictionary literals. To use a dictionary literal as the initial value of a dictionary, enclose a comma-separated list of key-value pairs in square brackets.
For example, the code sample below creates a dictionary with string keys and values.
let countryCodes = ["BR": "Brazil", "GH": "Ghana", "JP": "Japan"]
print(countryCodes)
// Prints "["BR": "Brazil", "JP": "Japan", "GH": "Ghana"]"