Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictionary print key and value in Swift 4 [duplicate]

Hello I tried a print dictionary items at Xcode9. Like this:

var items = ["Bear":"0", "Glass":"1", "Car":"2"]

for (key,value) in items{

print("\(key) : \(value)")

}

output:

Glass : 1
Bear : 0
Car : 2

Why output not like this: Bear: 0, Glass:1, Car:2 I dont understand this output reason.

like image 824
Mayday Avatar asked Dec 05 '22 14:12

Mayday


1 Answers

Dictionary :

A dictionary stores associations between keys of the same type and values of the same type in a collection with no defined ordering.

Each value is associated with a unique key, which acts as an identifier for that value within the dictionary. Unlike items in an array, items in a dictionary do not have a specified order.

Array - An array stores values of the same type in an ordered list.

Sets - A set stores distinct values of the same type in a collection with no defined ordering.

From Apple documentation

enter image description here

like image 192
Dharma Avatar answered Dec 30 '22 21:12

Dharma