Dictionary print keys and the value in SWIFT 4

See the answer in English> From which direction swift starts to read dictionaries? 1 one
Hello, I tried the print dictionary project in Xcode9. Like this:

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

for (key, value) in items{

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

}

Output:

< p>

Glass: 1
Bear: 0
Car: 2

Why the output is not like this: bear: 0, glass: 1, car: 2
I don’t understand the reason for this output.

Dictionary:

The dictionary stores the associations between the keys of the same type and the values ​​of the same type in the collection, without a defined ordering.

Each value is associated with a unique key, which acts as a dictionary Identifier of the value. Unlike the items in the array, the items in the dictionary have no specified order.

Array – The array stores the same type of value in an ordered list.

Collection-A collection stores different values ​​of the same type in a collection, in no defined order.

From the Apple documentation

enter image description here

See answer in English> From which direction swift starts to read dictionaries? 1
Hi I tried the print dictionary project in Xcode9. Like this:

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

for (key, value) in items{

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

}

Output:

< p>

Glass: 1
Bear: 0
Car: 2

Why the output is not like this: bear: 0, glass: 1, car: 2
I don’t understand the reason for this output.

Dictionary:

The dictionary stores the same type of keys and collections Association between values ​​of the same type without a defined ordering.

Each value is associated with a unique key, which serves as an identifier for that value in the dictionary. It is different from the items in the array. , The items in the dictionary have no specified order.

Array – arrays store the same type of values ​​in an ordered list.

Collection – collections store different values ​​of the same type in a collection , There is no defined order.

From the Apple documentation

enter image description here

Leave a Comment

Your email address will not be published.