What orginal order do you want to "preserve" ?
Probably the best is to cenvert dict to array, then sort on the correct order for future us.
Could do this (I assume the original order is the alphabetic of the key):
let dataConverted = (dataTable.map() { ($0.key, $0.value)}).sorted(by: { $0.0 <= $1.0 } )
print("dataConverted\n", dataConverted)
and get
dataConverted
[("1Cat", [99.95, 0.0, 0.05, 0.0, 0.0, 0.0, 0.04]), ("2Dog", [1.0, 1.0, 0.0, 98.0, 0.0, 0.0, 0.2]), ("3Mouse", [49.0, 43.2, 3.9, 0.0, 0.2, 3.7, 0.05]), ("4Gerbil", [40.3, 55.4, 3.0, 0.0, 0.4, 0.9, 0.05]), ("5Fish", [7.7, 90.8, 1.2, 0.0, 0.1, 0.2, 0.05])]
And now, order is preserved
print("\n Third form\n")
for _ in 1...4 {
for i in dataConverted {
print(i)
}
print("\n")
}
gets:
Third form
("1Cat", [99.95, 0.0, 0.05, 0.0, 0.0, 0.0, 0.04])
("2Dog", [1.0, 1.0, 0.0, 98.0, 0.0, 0.0, 0.2])
("3Mouse", [49.0, 43.2, 3.9, 0.0, 0.2, 3.7, 0.05])
("4Gerbil", [40.3, 55.4, 3.0, 0.0, 0.4, 0.9, 0.05])
("5Fish", [7.7, 90.8, 1.2, 0.0, 0.1, 0.2, 0.05])
("1Cat", [99.95, 0.0, 0.05, 0.0, 0.0, 0.0, 0.04])
("2Dog", [1.0, 1.0, 0.0, 98.0, 0.0, 0.0, 0.2])
("3Mouse", [49.0, 43.2, 3.9, 0.0, 0.2, 3.7, 0.05])
("4Gerbil", [40.3, 55.4, 3.0, 0.0, 0.4, 0.9, 0.05])
("5Fish", [7.7, 90.8, 1.2, 0.0, 0.1, 0.2, 0.05])
("1Cat", [99.95, 0.0, 0.05, 0.0, 0.0, 0.0, 0.04])
("2Dog", [1.0, 1.0, 0.0, 98.0, 0.0, 0.0, 0.2])
("3Mouse", [49.0, 43.2, 3.9, 0.0, 0.2, 3.7, 0.05])
("4Gerbil", [40.3, 55.4, 3.0, 0.0, 0.4, 0.9, 0.05])
("5Fish", [7.7, 90.8, 1.2, 0.0, 0.1, 0.2, 0.05])
("1Cat", [99.95, 0.0, 0.05, 0.0, 0.0, 0.0, 0.04])
("2Dog", [1.0, 1.0, 0.0, 98.0, 0.0, 0.0, 0.2])
("3Mouse", [49.0, 43.2, 3.9, 0.0, 0.2, 3.7, 0.05])
("4Gerbil", [40.3, 55.4, 3.0, 0.0, 0.4, 0.9, 0.05])
("5Fish", [7.7, 90.8, 1.2, 0.0, 0.1, 0.2, 0.05])