Dictionary (key , value) order

前端 未结 2 1250
一整个雨季
一整个雨季 2021-01-28 03:35

Assume i have the following code

var dictionary = [\"cat\": 2,\"dog\":4,\"snake\":8]; // mutable dictionary
var keys  = dictionary.keys
var values = dictionary.         


        
2条回答
  •  日久生厌
    2021-01-28 03:46

    No, it is not guaranteed to be in the same order. From documentation:

    Swift’s Dictionary type is an unordered collection. The order in which keys, values, and key-value pairs are retrieved when iterating over a dictionary is not specified.

提交回复
热议问题