0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Egor Kolyshkin
  • 117
  • 1
  • 10
  • 5
    _**Is it ok?**_ OK. Swift `Dictionary` is not order-preserving. Within the same invocation of an app, the order is stable. – OOPer Sep 09 '18 at 14:18

1 Answers1

0

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

Tony Merritt
  • 1,177
  • 11
  • 35