Syntax

Swift Create a Dictionary Syntax

In Swift, create a dictionary: creates key-value pairs — var ages = ["Ada": 36]

Quick Answer

Syntax
var ages = ["Ada": 36]
SwiftSyntax

Create a Dictionary

Code example
var ages = ["Ada": 36]

Creates key-value pairs.

Learn More

How to create a dictionary in Swift

  1. Open your Swift file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Swift Create a Dictionary Syntax

Use var ages = ["Ada": 36].

Related Syntax References

Frequently asked questions

What is the Swift syntax for create a dictionary?

Use this pattern: var ages = ["Ada": 36]

Can I copy this Swift code example?

Yes. Use Copy code and adapt the example to your program.

Is this Swift syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify