xxxxxxxxxx
var capitalCity = ["Nepal": "Kathmandu", "Italy": "Rome", "England": "London"]
print(capitalCity)
xxxxxxxxxx
var someDict:[String:Int] = ["One":1, "Two":2, "Three":3] // creates dictionary
var someVar = someDict["One"] // accesses the value of key "One"
print("The value of key = One is \(someVar)")
xxxxxxxxxx
let heights = [
"Taylor Swift": 1.78,
"Ed Sheeran": 1.73,
"Tom Arnold": 2.55
]
access the key by
print(heights["Taylor Swift"])
xxxxxxxxxx
// dictionary with keys and values of different data types
var numbers = [1: "One", 2: "Two", 3: "Three"]
print(numbers)
xxxxxxxxxx
var daysInMonth: [String: Int] = ["january": 31,"february": 28, "march": 31]
xxxxxxxxxx
let cityDistanceDict = Dictionary(uniqueKeysWithValues: zip(cities, Distance))
xxxxxxxxxx
// Declaring string to empty string
var myDictionary = [String : String]()
//Assigning data into a dictionary
myDictionary["sds"] = "red car"
// retriving value as optional string
print(myDictionary["sds"])