Strange dictionary in swift [duplicate]
Strange dictionary in swift [duplicate]
This question already has an answer here:
If I try something like this in a Swift playground:
let dic = ["1" : "!", "2" : "@","3" : "#"]
print(dic)
It prints:
["2": "@", "1": "!", "3": "#"]
And when I run it again it prints:
["1": "!", "2": "@", "3": "#"]
And then:
["3": "#", "2": "@", "1": "!"]
Is it ok? I use Xcode 10 beta.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Dictionary
1 Answer
1
Becuase dictionaries have key pair values (a key being "1" and value being "!") it doesnt sort them in order like an array it will be different each time, (Where an array stores a value at a position that it was added) you can grab the value of a dictionary by knowing the key so it doesnt matter
Is it ok? OK. Swift
Dictionary
is not order-preserving. Within the same invocation of an app, the order is stable.– OOPer
Sep 9 '18 at 14:18