3

here's my code:

var keys: [String:String] = ["id": "ID", "domain": "Domain", "bundled_domain": "Bundled Domain", "dns": "DNS", "registrar": "Registrar", "registrar_url": "Registrar URL", "sponsoring_registrar": "Sponsoring Registrar", "created": "Created", "updated": "Updated", "expires": "Expires", "whois_server": "Whois Server", "status": "Status"]

for (key, name) in keys{
    println(key)
}

But the result didn't follow order of the dictionary:

the result didn't follow order of the dictionary

So how can I make my for loop follow my dictionary order? Thanks!

He Yifei 何一非
  • 2,592
  • 4
  • 38
  • 69

1 Answers1

3

From Apples Document:

Swift’s Dictionary type does not have a defined ordering. To iterate over the keys or values of a dictionary in a specific order, use the global sorted function on its keys or values property.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165