How to Insert values in Dictionary in swift -


i first declare dictionary

let storesentenceordering = [string, int ](); 

then want insert value in getting error:

enter image description here

- can in following way

var cardictionary: [string:int] = [:]  // below subscript way of adding or updating value dictionary, if key not present key inserted assigned value else updated new value  cardictionary["ford"] = 345000 cardictionary["hyundai"] = 546788  print(cardictionary) 

- can use update add value existing dictionary

cardictionary.updatevalue(234500,forkey:("wolkswagen")) 

- dictionary can initialized in 1 following ways

var cardictionaryone: [string:int] = [:] var cardictionarytwo: [string:int] = () var cardictionarythree = ["ford":12345, "audi":57689] 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -