D
D
Dima Grib2021-05-07 10:34:11
Swift
Dima Grib, 2021-05-07 10:34:11

Correct sorting of numeric digits in Dictionary?

Greetings.
Who faced? I would be very grateful
How to correctly sort so that first there are hundreds, and after them thousands?

1. I get an array by Api,

var allEventsSort: [String: AllEvents] = [:]
allEventsSort = articles.events


2. Further in this array I do sorting
let sortedList = allEventsSort.sorted{ $0.0 > $1.0 }.map{$0.0}


3. And after sorting further, I transfer this entire array to the table model
handlerNews.events = sortedList

4. In this way, the Dictionary is sorted by the first three numbers, not taking into account the fourth, how to fix this?
sorted for (key) - 4047:
sorted for (key) - 4045:
sorted for (key) - 4025:
sorted for (key) - 4024:
sorted for (key) - 4023:
sorted for (key) - 402:
sorted for (key) - 4013:
sorted for (key) - 4009:
sorted for (key) - 400:
sorted for (key) - 399:
sorted for (key) - 396:
sorted for (key) - 394:
sorted for (key) - 392:
sorted for (key) - 383:
sorted for (key) - 380:
sorted for (key) - 3743:
sorted for (key) - 374:
sorted for (key) - 3737:
sorted for (key) - 3735:
sorted for (key) - 3733:
sorted for (key) - 3731:
sorted for (key) - 3727:
sorted for (key) - 3614:
sorted for (key) - 3612:
sorted for (key) - 3508:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2021-05-07
@briahas

As an option - translate strings into numbers and then compare ... or immediately work with numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question