Swiftyjson: Question: Ordered dictionary

Created on 6 Feb 2017  路  2Comments  路  Source: SwiftyJSON/SwiftyJSON

Is there anyway to ensure that when parsing a JSON to a dictionary that the dictionary will contain data in the same order as received in the JSON (an ordered dictionary)?

I know that it is not possible in "native" parsing with Swift, so I'm wondering if there's a SwiftyJSON way.

question

Most helpful comment

Unfortunately, dictionary is an un-order data struct in Swift and Objective-C. You might need to use an array with some kind of sort algorithm. eg. array.sort() { $0.age < $1.age }. Closing for now. Feel free to open it if need. :)

All 2 comments

Unfortunately, dictionary is an un-order data struct in Swift and Objective-C. You might need to use an array with some kind of sort algorithm. eg. array.sort() { $0.age < $1.age }. Closing for now. Feel free to open it if need. :)

thanks god I've found this question. Was very surprised by this native behaviour, spent a hours to figure out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amit-bhavsar picture amit-bhavsar  路  5Comments

patchthecode picture patchthecode  路  3Comments

marcheimendinger picture marcheimendinger  路  8Comments

MrLoveQD picture MrLoveQD  路  5Comments

otaran picture otaran  路  7Comments