Are keys and values in an NSDictionary ordered?

后端 未结 6 1243
孤街浪徒
孤街浪徒 2020-11-28 12:30

I mean: Is the order of keys and values in an NSDictionary always the same like how they were specified when initializing the NSDictionary? Or should I better maintain a sep

6条回答
  •  囚心锁ツ
    2020-11-28 12:38

    keys are never guaranteed to be in the same order when accessing an NSDictionary. If the keys can be compared (which I assume they can be given your question), then you can always sort them if you need to access them in sorted order.

    You would need to do this by reading the keys into an array first and sorting the array of course.

提交回复
热议问题