Ordered map in Swift

前端 未结 12 1168
忘掉有多难
忘掉有多难 2020-11-28 09:24

Is there any built-in way to create an ordered map in Swift 2? Arrays [T] are sorted by the order that objects are appended to it, but dictionaries

12条回答
  •  渐次进展
    2020-11-28 10:15

    As others have said, there's no built in support for this type of structure. It's possible they will add an implementation to the standard library at some point, but given it's relatively rare for it to be the best solution in most applications, so I wouldn't hold your breath.

    One alternative is the OrderedDictionary project. Since it adheres to BidirectionalCollection you get most of the same APIs you're probably used to using with other Collection Types, and it appears to be (currently) reasonably well maintained.

提交回复
热议问题