How to create key value dictionary in Swift

2 Answers

0 votes
let dict = [
	   "swift": 5,
	   "c": 1,
	   "java": 4,
	   "c++": 8 ]

for (key, value) in dict {
    print("key = \(key) - value = \(value)")
}



/*
run:

key = c++ - value = 8
key = java - value = 4
key = swift - value = 5
key = c - value = 1

*/

 



answered Dec 11, 2022 by avibootz
0 votes
var dict:[String:Int] = ["swift":6, "c":4, "java":1, "c++":9]

for (key, value) in dict {
    print("key = \(key) - value = \(value)")
}



/*
run:

key = swift - value = 6
key = c - value = 4
key = c++ - value = 9
key = java - value = 1

*/

 



answered Dec 11, 2022 by avibootz
...