<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Dictionary/init(dictionaryLiteral:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SD17dictionaryLiteralSDyxq_Gx_q_td_tcfc"
  },
  "title" : "init(dictionaryLiteral:)"
}
-->

# init(dictionaryLiteral:)

Creates a dictionary initialized with a dictionary literal.

```
init(dictionaryLiteral elements: (Key, Value)...)
```

## Parameters

`elements`

The key-value pairs that will make up the new
dictionary. Each key in `elements` must 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"]"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)