Are keys and values in an NSDictionary ordered?

后端 未结 6 1239
孤街浪徒
孤街浪徒 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:47

    No, they are not ordered. As long as you don't add or remove any elements from the dictionary, they will remain in the same order, but as soon as you add or remove an element, the new order will be completely different.

    If you need the keys/values to be ordered, use an NSArray (or some other ordered data structure) instead.

提交回复
热议问题