ios - Dictionary returns consecutive/shuffled values when iterating in swift -


this question has answer here:

i have following dictionary

var data : [string: string] = ["dev" : "dev", "qua" : "qua" , "sit" : "sit", "uat" : "uat", "prod" : "prod"] 

i iterate using loop , following values

sit prod dev uat qua 

ie consecutive values

i have following code iterate

for (key, value ) in data.enumerate() {     print(value) } 

i want these values in same format of declaration.

swift dictionary type unordered type. on every for in loop can receive different ordered result (in theory). should choose other data structure if wish keep order, array<(string, string)> example:

var data: array<(string, string)> = [("dev", "dev"), ("qua", "qua"), ("sit", "sit"), ("uat", "uat"), ("prod", "prod")]  element in data {     print(element.1) } //dev //qua //sit //uat //prod 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -