为什么[NSDictionary allKeys]不返回一个集合? [英] Why doesn’t [NSDictionary allKeys] return a set?

查看:193
本文介绍了为什么[NSDictionary allKeys]不返回一个集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个原因 NSDictionary NSArray 而不是 ?文档已经声明了数组中键的顺序是未定义的,使用一个集合是合乎逻辑的。

Is there a reason for NSDictionary to return its keys as NSArray instead of NSSet? The documentation already states that the order of the keys in the array is undefined, it would sound logical to use a set.

推荐答案

集合往往在API设计中有些被忽略。它们将被包括在大多数时间,但通常在所有其他标准数据结构之后。除此之外,除了最近的NSFastEnumeration之外,在Objective-C中没有通用收集或序列协议 - 每个收集类都完全独立于所有其他类 - 并且在API之后切换到集合变得非常困难已经写入返回数组。

Sets tend to be somewhat neglected in API design. They'll be included most of the time, but usually long after all the other standard data structures. Add on top of that the fact that besides the very recent NSFastEnumeration, there is no general collection or sequence protocol in Objective-C — every collection class is completely independent of all the others — and it becomes very hard to switch to sets after an API has already been written that returns arrays.

这篇关于为什么[NSDictionary allKeys]不返回一个集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆