0 votes
in Swift by
What is a dictionary?

1 Answer

0 votes
by
Dictionaries are an association of an unordered collection of key-value pairs. Each value is associated with a unique key, which is a hashable type such as a number or string. We can use the dictionary concept in swift programming language whenever we want to obtain the values based on a key value.

Syntax of Swift Dictionaries:

Following is the syntax of defining a dictionary in the Swift programming language.

Dictionary<Key, Value> ()

Or

[Key: Value] ()

Creating Dictionaries in Swift:

Following are the different ways of creating a dictionary with key-value pairs in the declaration.

// using Dictionary

Var names = Dictonary<String,Int> ()

Names = [“Ajay”: 1, “Mohit”: 2]

print(names)

// it prints [Ajay: 1, Mohit: 2]
...