1.

Explain dictionary in Swift.

Answer»

SWIFT programming defines a dictionary as an unordered collection of items. It stores items in key-value pairs. A dictionary USES a unique identifier called a key to store an ASSOCIATED value which can later be referenced and retrieved through the same key. 

Syntax: 

var Dict_name = [KeyType: ValueType]()

Example: 

var examresult= ["Rahul": "79", "Aditya": "86", "ADITI": "67"] print(examresult)

Output: 

["Rahul": "79", "Aditya": "86", "Aditi": "67"]

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

  • Keys are "Rahul", "Aditya", "Aditi"
  • VALUES are "79", "86", "67"


Discussion

No Comment Found