I quickly learn and try to understand dictionaries. I'm used to PHP where you can write the following ...
$dataPoints = Array("A"=>1,"B"=>2,"C"=>3);
foreach($dataPoints as $value) {
echo($value);
}
In this example, the values ββwill be displayed in the order - 1, 2, 3
My quick code looks like this:
var dataPoints: Dictionary<String,Int> = ["A":1,"B":2,"C":3]
for (key, value) in dataPoints {
print(value)
}
However, the values ββcome out in unexpected order. Is there anything clean that I can do to save the values ββin the order in which they were created, or will the quick dictionary never be sorted?
source
share