How to update value in dictionary with Swift

2 Answers

0 votes
var dic : [String: Int] = ["Swift": 4, "Python": 7, "Java": 6, "PHP": 5]
  
dic.updateValue(88, forKey: "Swift")

for (key, value) in dic {
    print(key, value)
}

  
  
/*
run:
  
Python 7
Java 6
Swift 88
PHP 5
  
*/

 



answered Sep 20, 2020 by avibootz
0 votes
var dic : [String: Int] = ["Swift": 4, "Python": 7, "Java": 6, "PHP": 5]
   
dic["Swift"] = 99
 
for (key, value) in dic {
    print(key, value)
}
 
   
   
   
/*
run:
   
Swift 99
Python 7
Java 6
PHP 5
   
*/

 



answered Jun 14, 2023 by avibootz

Related questions

1 answer 181 views
1 answer 176 views
2 answers 184 views
1 answer 163 views
2 answers 187 views
...