How to Insert values in Dictionary in swift -
i first declare dictionary
let storesentenceordering = [string, int ]();
then want insert value in getting error:
- 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
Post a Comment