Sort NSDictionary

前端 未结 3 1235
名媛妹妹
名媛妹妹 2021-01-28 06:25

I got NSDictionary with pairs like :

Key -> Value:
@\"home\" -> @\"blue\"
@\"family\" -> @\"green\"
@\"work\" -> @\"red\"


        
相关标签:
3条回答
  • 2021-01-28 06:45

    You can't sort an NSDictionary. If you want , you could create an object to hold the key and value in it, then add to an array and use a sort descriptor to sort on the key field.

    0 讨论(0)
  • 2021-01-28 06:47

    NSDictionary is not an ordered collection, however you can sort its keys using comparators like keysSortedByValueUsingComparator, keysSortedByValueUsingSelector.

    0 讨论(0)
  • 2021-01-28 06:57

    You can access the keys in a sorted order with method like keysSortedByValueUsingComparator, keysSortedByValueWithOptions or keysSortedByValueUsingSelector. But by definition a NSDictionary itself has no notion or order.

    0 讨论(0)
提交回复
热议问题