Why doesn’t [NSDictionary allKeys] return a set?

前端 未结 5 1106
南笙
南笙 2021-02-12 16:10

Is there a reason for NSDictionary to return its keys as NSArray instead of NSSet? The documentation already states that the order of the

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 16:51

    My guess is that, since -allKeys returns a copy of the keys (it's not backed by the dictionary) that creating an NSSet is a lot of overhead (building a tree or hash table or whatever) when compared to just dumping the keys into a flat array.

提交回复
热议问题