Explain Dictionary in Swift.

bookmark

Swift programming describes a dictionary as an unordered collection of items. It stores items in key-value pairs. A dictionary uses a specific identifier called a key to store an associated value which can be referenced and recovered through the same key.

Syntax:

 var Dict_name = [KeyType: ValueType] ()

Example:

var examresult= [“Nick”: “34”, “Aditya”: “26”,  “Emma” : “94”]

print(examresult)

Output:

[“Nick” : “34”, “Aditya” : “26”, “Emma” : “94”]

In the above example, we have a dictionary named examresult. Here,

Keys are “Nick,” “Aditya,” “Emma”

Values are “34”, “26”, “94”